Reputation: 73
I use the line below in my C# winform app, this works great but occasionally if the program is being run from the command line I get an error that the config.xml
file cannot be found. This is because the 'working directory' is different (I think), I need to say "load config.xml from current directory", how would I do this?
docXML.Load("config.xml");
Thanks Jonathan
Upvotes: 5
Views: 10304
Reputation: 1309
string Path = "";
string Filename = ConfigurationManager.AppSettings("Filename");
for loading from current directory
Path = System.Web.HttpContext.Current.Server.MapPath(Filename);
for loading from Base directory
Path = AppDomain.CurrentDomain.BaseDirectory + Filename;
Upvotes: 3
Reputation: 4638
string fileName = Path.Combine(Application.StartupPath, "config.xml");
Upvotes: 8