I pulled this code from a different application we use to write/read data between an xml and a form. The information I am trying to read is just a string of a directory path that the user picks on the form.
Here is the XML file
Here is the code:
It is erroring on Me.txtImportPat h.Text = xSettings.Selec tSingleNode("ro ot/settings/importdir").Inn erText and the error I'm getting is:
Object reference not set to an instance of an object.
I don't know why this is happening as it works great in the application I grabbed this code from.
THANKS!
Here is the XML file
Code:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<settings>
<importdir>test</importdir>
<exportdir>test</exportdir>
<archivedir>test</archivedir>
</settings>
</root>
Code:
Public Class Form1
Dim xSettings As New System.Xml.XmlDocument
Dim xSettingsFileName As String = String.Empty
Dim sFilePath As String
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
xSettingsFileName = "loaderconfig.XML"
sFilePath = My.Application.Info.DirectoryPath & "\" & xSettingsFileName
'sFilePath = "C:\My Documents\Visual Studio 2005\Projects\OTPP Loader\OTPP Loader\bin\Debug\loaderconfig.xml"
refreshconfig()
End Sub
Public Sub refreshconfig()
'Clear out the text boxes to ensure nothing is there when we load the settings
Me.txtImportPath.Text = String.Empty
Me.txtExportPath.Text = String.Empty
xSettings.Load(sFilePath)
Me.txtImportPath.Text = xSettings.SelectSingleNode("root/settings/importdir").InnerText
Me.txtExportPath.Text = xSettings.SelectSingleNode("root/settings/importdir").InnerText
Object reference not set to an instance of an object.
I don't know why this is happening as it works great in the application I grabbed this code from.
THANKS!
Comment