© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
11 replies
c0nstant

Cannot access file because it's being used by another process

I am getting the following error when I try to run my program:
System.IO.IOException: 'The process cannot access the file because it is being used by another process.'
System.IO.IOException: 'The process cannot access the file because it is being used by another process.'


I googled around and most suggestions want you to close the file stream when you are done with a file however the files that I am triyng to rename don't have a close method.

Here is my code:
var output = @"E:\demo.txt";
var ext = RandomStringNS(12) + " - REST Database";
                    Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(output, ext);
var output = @"E:\demo.txt";
var ext = RandomStringNS(12) + " - REST Database";
                    Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(output, ext);

So when I run this on a directory, it works on the first and sometimes the second file until something gets in the way. So what I need to do is force my program to rename files.

Any solutions to this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ "cant open file due to it being used by another process"
C#CC# / help
3y ago
storageFile.CopyAsync break being used by another process
C#CC# / help
4y ago
Access file that is being used by another application using FileStream
C#CC# / help
4y ago