brdrok
asked on
Error: The process cannot access the file because it is being used by another process
Hello,
I am getting a:
The process cannot access the file because it is being used by another process
error message. How do I handle this problem? Below is my code:
public static void MoveFile(string fileName, string destinationFolder)
{
try
{
string source = Path.Combine(Constants.Com pleteStagi ngFolderPa th, fileName);
string destination = Path.Combine(destinationFo lder, fileName);
File.Copy(source, destination, false);
}
catch (System.IO.IOException ioEx)
{
System.Guid guid = System.Guid.NewGuid();
if(ioEx.Message.EndsWith(" already exists."))
{
string source = Path.Combine(Constants.Com pleteStagi ngFolderPa th, fileName);
string newFileName = fileName.Insert(fileName.L ength - 4, "_v" + DateTime.Now.Hour.ToString () + DateTime.Now.Minute + DateTime.Now.Second);
File.Move(source, Path.Combine(destinationFo lder, newFileName)); <===Generating error
}
}
catch (Exception ex)
{
//do something else
}
}
thanks
I am getting a:
The process cannot access the file because it is being used by another process
error message. How do I handle this problem? Below is my code:
public static void MoveFile(string fileName, string destinationFolder)
{
try
{
string source = Path.Combine(Constants.Com
string destination = Path.Combine(destinationFo
File.Copy(source, destination, false);
}
catch (System.IO.IOException ioEx)
{
System.Guid guid = System.Guid.NewGuid();
if(ioEx.Message.EndsWith("
{
string source = Path.Combine(Constants.Com
string newFileName = fileName.Insert(fileName.L
File.Move(source, Path.Combine(destinationFo
}
}
catch (Exception ex)
{
//do something else
}
}
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad to help.
ASKER