The process aspnet_wp is a surviver !

N

news.iq.ca

Hi. I am trying to use a treeview - after a few attempts, it works, but only
up to a point - my exercise was to dynamically create nodes in the treeview.
I read about binding the treeview to a XML file. Okay, so I decided to
complicate my exercise and to create the XML file on the fly. I am using
this code to browse through the list of my other projects, create the XML
file and then populate the treeview. I am not using the XML writer object
because I did not reach that point with my learning, so I am writing it "the
old way":

<code>
Private m_strPath As String = "C:\Documents and
Settings\Administrator\My Documents\My
Projects\ASPNETProjects\vsnet\ThirdPartyControls\TreeNodes.XML"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
CreateXMLFile()
TreeView1.TreeNodeSrc = m_strPath
TreeView1.DataBind()
End If
End Sub

Private Sub CreateXMLFile()

Dim objDirectory As Directory
Dim ProjectInfo As FileInfo

Dim lstFiles As String()
Dim strProjectLongName As String
Dim strProjectShortName As String

Dim strmFile As StreamWriter
Dim objStringBuilder As New StringBuilder()

Const PROJECTS_PATH As String = "C:\Documents and
Settings\Administrator\My Documents\My Projects\ASPNETProjects\notepad\"

strmFile = File.CreateText(m_strPath)
strmFile.WriteLine("<TREENODES>")
strmFile.WriteLine("<TREENODE TEXT=""ASP.NET PROJECTS"">")

lstFiles = objDirectory.GetFiles(PROJECTS_PATH, "*.aspx")
For Each strProjectLongName In lstFiles
ProjectInfo = New FileInfo(strProjectLongName)
strProjectShortName = ProjectInfo.Name
objStringBuilder = New StringBuilder()
objStringBuilder.Append("<TREENODE TEXT=""" &
strProjectShortName & """ NAVIGATEURL =
""HTTP:\\LOCALHOST\ASPNETPROJECTS\NOTEPAD\")
objStringBuilder.Append(strProjectShortName)
objStringBuilder.Append("""" & "/>")
strmFile.WriteLine(objStringBuilder.ToString)
Next strProjectLongName

strmFile.WriteLine("</TREENODE>")
strmFile.Write("</TREENODES>")
strmFile.Flush()

strmFile.Close()
strmFile = Nothing
objStringBuilder = Nothing
lstFiles = Nothing
objDirectory = Nothing
End Sub
</code>

This code works fine, but ... if I run the application one more time, I get:
________________________________________________
Exception Details: System.IO.IOException: The process cannot access the file
"C:\Documents and Settings\Administrator\My Documents\My
Projects\ASPNETProjects\vsnet\ThirdPartyControls\TreeNodes.XML" because it
is being used by another process.
________________________________________________

I also discovered that I can't even delete the "TreeNodes.XML" file IN
EXPLORER (!) because the file is locked.. VERY STRANGE - this happens EVEN
if I close VS.NET !

I discovered that the only way out is to kill the process "aspnet_wp" in
task manager - it gets recreated instantly, even with VS.NET closed (!?),
but at least I can now delete the file in Explorer. So the sequence to make
it work is this: run the app the first time - stop it - kill the aspnet_wp
process (it gets recreated) - now I can run the app again without having the
above-mentioned error.

What's with this lock ??? Am I doing something wrong in this code ? I even
set to nothing almost all objects in my app, except the strings, even if
this is useless....

Thank you.
Alex.
 
J

Jiri Richter [MSFT]

Alex,

The aspnet_wp process is part of ASP.Net and is responsible for executing
the code behind your page. Here's what I think is happening with the lock.
When you set the TreeNodeSrc property and call DataBind method of the
TreeView object the object open the XML file and doesn't close it. It seems
that the TreeNodeSrc property can be assigned either a file name or directly
the XML data as a System.String. You can try that to get around the issue
with the lock.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top