
May 12th, 2003, 05:02 PM
|
|
Registered User
|
|
Join Date: May 2003
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
How do I close a text file?
I have a web form that allows users to upload text files to the web server then my code opens the text file and stores the data to a database. That all works. However, if the text file is not in the correct format, I allow the user to fix the text file and try to upload again. My problem is I don't know how to close the text file. When the user try to upload again I receive the following error. I believe it's because the file is still open and locked. <br><br>Access to the path "c:inetpubwwwrootWylePricingSystemWeeklyLaborArchiv eBAWeeklyHours050403.txt" is denied. <br><br>I tried to fix my problem by catching the error, then trying to close the objStreamReader hoping it would close the file so I can delete it. <br><br>Does anyone know how I can solve my problem? Look below at what I trying to do. <br><br>Dim myFileName as string <br>Dim objStreamReader As StreamReader <br><br>myFileName=session("filename") <br>try <br><br>objStreamReader = File.OpenText("c:inetpubwwwrootWylePricingSystemWeeklyLaborArchiv e"" + myFileName) <br>. <br>. <br>. <br>catch err As Exception <br> Response.Write(err.Message.ToString) <br> objStreamReader.DiscardBufferedData() <br> objStreamReader.Close() <br><br><br> File.Delete("c:inetpubwwwrootWylePricingSystemWeeklyLaborArchiv e"" + myFileName) <br> End Try <br><br>Thanks, <br><br>James
|