XmlTextReader Exception

A

Aaron

I have a function which reads in selected tool names within a list box from
an XML file and that function is being called in my Load function for the
form. I can't even load the program in the emulator because I keep getting
the following error:

"An unhandled exception of type 'System.IO.IOException' occured in
mscorlib.dll"

This is the line of code that's throwing the error:

XmlTextReader xmlTr = new XmlTextReader(xmlFile);

When I press the "continue" button in the message box, the program just
exits and I never get to test it. This is written in C# and I'm new to the
language and can't figure out a way around this. Below are my two
functions...
private void ReadFile()
String xmlFile = "..\\Tools.xml";
XmlDocument xmlDoc = new XmlDocument();

XmlTextReader xmlTr = new XmlTextReader(xmlFile);
while (xmlTr.Read())
{
if (xmlTr.Name == "Tool")
{
if (xmlTr.NodeType == XmlNodeType.Element)
{
lstTools.Items.Add(xmlTr.ReadString());
}
}
}
xmlTr.Close();

xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFile);
}

private void frmStartup_Load(object sender, System.EventArgs e)
{
lstTools.Items.Clear();
ReadFile();
}

Any help or code snippets would be greatly appreciated.
Thanks
 
A

Alex Feinman [MVP]

Relative paths are not supported as there is no concept of current
directory.
 

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

Top