I have a basic aspx page for the user to select the month & year. They then
click a button to generate a report. The following sequence happens:
- Temp directory is created (if it exists already, it is deleted first)
- A simple aspx file is built in code and written to the temp directory with
a StreamWriter
- A View Report button is displayed for the user
The View Report button is a HyperLink control that targets a blank window.
When clicked the temp aspx file in the temp directory is displayed in the
window.
Once the temp aspx file is accessed, if the user tries to run the report
again, an error is thrown. It appears that aspnet_wp.exe has a handle on the
temp directory which interferes with the following code:
If Directory.Exists(strPath) = True Then
Directory.Delete(strPath, True)
End If
Directory.CreateDirectory(strPath)
....
dsDataSet.WriteXml(strPath & "\report.xml")
....
objStreamWriter.Write(strHtml)
The error only occurs the first time the report is run after viewing the
file. The error is caused by the WriteXml command not having a directory to
write to. So the directory gets deleted but it does not get recreated.
Re-running the report again at that poit is successfull.
Here's a summary of how to recreate the error:
Run report = success
Don't view file
Re-run report = success
View file
Re-run report = failure
Re-run report = success
This appears to be an issue where aspnet_wp.exe has a handle on a
file/directory that is part of the web application. Is there a way to keep
hat from happening?