I’m trying to load a document with xml in c#
the name of xml file is variable, here is problem…
string filename="test01.xml";
XmlDocument root = new XmlDocument();
root.Load(filename);
the above code give me error: unable to connect to remote server or unable to load
but the following code works
XmlDocument root = new XmlDocument();
root.Load("test01.xml");
why is that?
You can try to specify the whole path (absolute path) to the file (not only the filename).
So instead of writing “test01.xml” you can try to write “C:\[… path to the file here]\test01.xml” and it should work as intended.
If you specify only the file name, the application will probably look for the file in the current directory (value in
Environment.CurrentDirectory). I just tested this in a sample application.It’s worth mentioning that if you use
FileNameproperty fromOpenFileDialogclass as a case with ‘using variable’, it contains PATH to the file (despite its name ;)).