I want to update a file. I opened the file and then tried to copy another file content to it but got the exception:
The process cannot access the file "fileURL" because it is being used by another process.
Is there any solution to this.
Depends on how you are doing it, but the best guess (i.e. the usual mistake) is that when you open the file, you don't Dispose of all the elements that are involved. If you open the file with a stream in one method, and allow the stream to go out of scope at the end, then the file is still open and locked until the Garbage Collector comes along and Disposes of it for you. this may not happen for a very long time! Until it does happen, all other accesses will get "the fvile is in use by another process" because it is - windows does not know you have finished with it until the stream is Disposed.
Change the way you are accessing the file to either manually call the Dispose method, or enclose the code in a
Sorry I can't be more specific, but without relevant code fragments, it is impossible!
The reason of error is bit simple. you have open a file but not properly close it. the instance remain live in memory.
write .Close() and .Dispose() method to release memory.
GC.close() will work for you after dispose()
The problem is if you have deployed the file in IIS and then modfiying the file using an IDE it might not allow you to overwrite because the file is beign opened as the IIS turn on and off with the system automatically .So you want to modify your file go IIS and stop the IIS engine and modify your file.
I have used this to solve my problem hope if you are finding the same problem the could help out from this issue.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)