Click to See Complete Forum and Search --> : Opening XML File via Relative Path


arrtchiu
July 25th, 2009, 09:56 PM
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:

XmlReader r = XmlReader.Create("~/App_Data/LwICTProxy_Services.xml");


If anyone can help me it would be greatly appreciated :)

MuneebShakoor
July 26th, 2009, 07:46 AM
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");

arrtchiu
August 7th, 2009, 06:33 AM
Awsome, thanks very much!