[ACCEPTED]-The process cannot access the file because it is being used by another process-c#
Accepted answer
using (FileStream fs =
new FileStream(filePath,
FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
//...
http://msdn.microsoft.com/en-us/library/system.io.fileshare.aspx
Your log may be write locked, so try with 1 FileShare.ReadWrite.
Try to add the FileShare option, see if 3 that helps:
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
EDIT: corrected code, not FileShare.Read
but 2 FileShare.ReadWrite
does the trick (as Guillaume showed as 1 well). The reason: you want to open your file and allow others to read and write it at the same time.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.