File.Move error in C#
- by Bi
Hi
I am trying a simple move as shown below and get the following error: "The process cannot access the file because it is being used by another process." How do I fix this? Thanks.
FileInfo file1 = new FileInfo(srcFile);
if (file1.Exists)
{
FileInfo file2 = new FileInfo(destFile);
if (!file2.Exists)
{
try
{
File.Move(srcFile, destFile);
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
}
}
}