Hello all
I am using WebMethod and File.Move
But my problem is the file is being locked by the WebMethod and it cannot be moved again (I want to rename it, not move it)
The exception thrown is "The process cannot access the file because it is being used by a another process"
How do I solve this?
I probably googled for half an hour
Here is my code:
Code:[WebMethod] public void EditFile(string FilePath, string NewName, string OldName) { File.Move(FilePath + OldName, FilePath + NewName); }
Are you using another method to access the path of the file or get the file name? There has to be something else going on before this method is called in order for that error to be thrown. Another thing you may want to try is see if you can use File.Copy and copy the old file to the new name and then use File.Delete to remove the old one. See if that throws an error. It's not the best method but you can use that for debugging to see if it gives the same error message.
Let me know if you need any further assistance.![]()
-CDG10620
Software Developer
I am sure that you left a FileReader or FileStream instance object left open in your code.
use the
Code:FileStream fs=new FileStream(); fs.close(); //use this to close the file handles
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks