Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Problems with Text Files


Message #1 by "Hugh McLaughlin" <hugh@k...> on Thu, 21 Nov 2002 03:52:02
Hello Everyone and thanks for your help in advance.  I have written and 
ASPX page that writes a small amount of data to a text file stored on the 
server.  It is currently the only application that does anything to this 
text file.  However, on occasion, when I run the page, I get an error 
that another application or process is currently using the file.  I am 
not sure where to start looking to trouble shoot this issue.  Any help on 
this would be greatly appreciated.  Thanks.
Message #2 by "Ken Tola" <ktola@c...> on Fri, 22 Nov 2002 11:37:45
     I have a program that parses logfiles into a standard text file on a 
nightly basis.  When first developing this program it also suffered from 
these "file being used by another program" issues.
     From what I can determine, there are three causes for this, two of 
which I have solved and the other I avoid!  First, you need to explicitly 
call the close method of your streamwriter object at the end - the garbage 
collector is just not reliable enough.  Second, if you are using a 
streamreader, you need to call the DiscardBufferedData before calling its 
close method.
     The last one, the one I avoid, is using the File object 
(system.io.file) to move or copy files around.  For some reason this 
object always locks up the file and I have not been able to find a way to 
manually release the target file when I am finished.
     I hope this helps!

                                  Ken

  Return to Index