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 dont know how to close the text file. When the user try to upload again I receive the following error. I believe its because the file is still open and locked.
Access to the path "c:\inetpub\wwwroot\WylePricingSystem\WeeklyLaborArchive\BAWeeklyHours050403.txt" is denied.
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.
Does anyone know how I can solve my problem? Look below at what I trying to do.
Dim myFileName as string
Dim objStreamReader As StreamReader
myFileName=session("filename")
try
objStreamReader = File.OpenText("c:\inetpub\wwwroot\WylePricingSystem\WeeklyLaborArchive\" + myFileName)
.
.
.
catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
objStreamReader.DiscardBufferedData()
objStreamReader.Close()
File.Delete("c:\inetpub\wwwroot\WylePricingSystem\WeeklyLaborArchive\" + myFileName)
End Try
Thanks,
James
Access to the path "c:\inetpub\wwwroot\WylePricingSystem\WeeklyLaborArchive\BAWeeklyHours050403.txt" is denied.
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.
Does anyone know how I can solve my problem? Look below at what I trying to do.
Dim myFileName as string
Dim objStreamReader As StreamReader
myFileName=session("filename")
try
objStreamReader = File.OpenText("c:\inetpub\wwwroot\WylePricingSystem\WeeklyLaborArchive\" + myFileName)
.
.
.
catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
objStreamReader.DiscardBufferedData()
objStreamReader.Close()
File.Delete("c:\inetpub\wwwroot\WylePricingSystem\WeeklyLaborArchive\" + myFileName)
End Try
Thanks,
James