I have an ASP.NET application where in my APP_Code folder I have a class. In that I have the following code to read the content of an XML file which is in my root folder:
XmlDocument xmlSiteConfig = new XmlDocument();
xmlSiteConfig.Load(System.Web.HttpContext.Current.Server.MapPath("../myConfig.xml"));
My Root folder is having several folders with nested inner folders for some. From the first level of folders when I call the piece of code in the Appcode class, I am able to load the XML file correctly since the path is correct. Now if I call the same piece of code from an inner folder, I am getting an error. If I change the code to the below it will work fine
xmlSiteConfig.Load(System.Web.HttpContext.Current.Server.MapPath("../../myConfig.xml"));
How can I solve this? I don't want to change the file path for various calls to this code.With what piece of code I can solve the issue so that the program will load the XML file irrespective of the calling position.