I'm using "System.IO.File.Copy(recovery, set, true);" to copy recovery.txt over set.txt
The problem is, i think, the file is still in use when I attempt to further alter it. (the compiler throws an exception)
I've had a similar issue when using StreamWriter, however that was fixed by using writerObj.Close(). Is there anything similar for system.io?
This is probably an easy fix, however, i couldn't find a fix on msdn. Using google i must not be phrasing the question right as the only results include StreamWriter/StreamReader
EDIT:
I think i've managed to pinpoint the issue. After i copy the backup of set.txt i load the new values from the file and that seems to keep the file opened. The way i load values off the file is: use StreamReader to go through the file line by line and save numeric values in an array. Then i assign each member of the array to a functional parameter. My best guess is that somehow the functional parameters are still linked to the text file. Any suggestions?
Loading
Stefan CazacuPosted Oct 7, 2013, 4:01 AM
Prashant SrivastavaPosted Oct 5, 2013, 8:35 AM
You are facing the problem because the instance of the file is not killed. So, the solution for this is KillProcess once your are done with your activity.
HOW to Check :
1. Open task manager.
2. Go to Process.
3. You will see multiple instances for that.
Solutions Steps :
1. Open file (via code).
2. Read the data, Hold that in any object.
3. Close the file.
4. Kill Process of that file.
5. use that same object to copy to place where ever you want.
NOTE :
Above step need to below implemented in code in order to avoid logging of multiple instance of particular user for a file (.docx, .xls, .txt) so as to avoid server problem hanging problem.
Regards,
Prashant Srivastava
VulpesPosted Oct 4, 2013, 7:20 PM
As you know, both StreamReader and StreamWriter have Close() methods, though if you use them with the 'using statement', calling Close() is unnecessary.
Otherwise the chances are that the file has been opened with a different process, such as Notepad, but not yet closed.