Opening XML File via Relative Path
Hi guys,
I'm sure this is a total noob question to you, but I'm finding it quite hard to locate an answer to this!
I want to be able to read strings from an XML file so I can use them in my code.
The thing is, I want to do this from within a class, which means I can't use the xmlDataSource control (like <asp:xmlDataSource.....)
All of the examples I find either use the xmlDataSource control (which seems like it needs to be put on a page) or a relative path (like @"C:\myxmlfile.xml")
I can't use a relative path because that will prevent the app from being moved around (without having to modify variables)
have been trying it like this:
Code:
XmlReader r = XmlReader.Create("~/App_Data/LwICTProxy_Services.xml");
If anyone can help me it would be greatly appreciated :)
Re: Opening XML File via Relative Path
Well, if you have a web application then you can use,
XmlReader r = XmlReader.Create(Server.MapPath(".") + "/App_Data/LwICTProxy_Services.xml");
or desktop application use,
XmlReader r = XmlReader.Create(Application.StartupPath + "/App_Data/LwICTProxy_Services.xml");
Re: Opening XML File via Relative Path
Awsome, thanks very much!