part of a console application I have is built to delete an unwanted order file out of a directory on a server we use. This part of the code works fine when I run it off of my local machine, but when we run it on the server it self (it will be a scheduled task), it no longer deletes the file.
try
{
System.IO.File.Delete(@"\\ServerName\ProductionFileShare\Orderfiles\FileDir\" + fileName);
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
return;
}
The filename is just the storeorder.txt.
As I said, this works just fine on my local computer, but does not delete the file when we run this program from the server itself. Any ideas?
UPDATE: The exception message is: The process cannot access the file '\ServerName\ProductionFileShare\Orderfiles\FileDir\storeorder_07062014_16-25-0.txt' because it is being used by another process.
This is strange to me, since it works on my computer. I will add some garbage collection and see what happens.
UPDATE #2: Apparently that fixed it! That was an unexpected solution. Thanks to everyone for taking the time to comment, I really appreciate it.