C#C
C#3y ago
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.'

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);

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?
Was this page helpful?