What I am trying to do is really basic. All I want is to be able to update the inner text of a couple nodes and then save the XML file. However, whenever I try to save the file, the program crashes and I get this error:
I understand what the error means, but I don't know why it is occurring since nothing else should be using that file. Here is the code:
Here is the XML:
Do any of you understand why I cannot save the xml file or perhaps see something else that I am doing wrong? I am open for changing this around just to make it work.
System.IO.IOException "The process cannot access the file 'C:\Documents and Settings\mjason\Desktop\Projects\Global Distribution ? Inventory\Global Distribution ? Inventory\bin\Debug\Settings.xml' because it is being used by another process."
I understand what the error means, but I don't know why it is occurring since nothing else should be using that file. Here is the code:
Private Sub SaveSettings(ByVal Username As String)
Dim xmlDoc As New XmlDocument
Dim xmlRememberNode As XmlNode
Dim xmlUsernameNode As XmlNode
Dim xmlPath As String
' Get the Settings.xml path
xmlPath = Application.StartupPath() + "/Settings.xml"
' Open Settings.xml
xmlDoc.Load(xmlPath)
' Get current xml data for Remember and Username
xmlRememberNode = xmlDoc.SelectSingleNode("//Settings/Remember")
xmlUsernameNode = xmlDoc.SelectSingleNode("//Settings/Username")
' Save the settings
If chkboxRemember.Checked Then
xmlRememberNode.InnerText = "1"
xmlUsernameNode.InnerText = Username
Else
xmlRememberNode.InnerText = "0"
xmlUsernameNode.InnerText = Nothing
End If
xmlDoc.Save(xmlPath)
End Sub
Here is the XML:
<?xml version="1.0" encoding="utf-8" ?>
<Settings>
<Remember>0</Remember>
<Username>Name</Username>
<DatabasePath>Path</DatabasePath>
</Settings>
Do any of you understand why I cannot save the xml file or perhaps see something else that I am doing wrong? I am open for changing this around just to make it work.