5

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

2 Answers 2

8
string fileName = Path.Combine(Application.StartupPath, "config.xml");
Sign up to request clarification or add additional context in comments.

Comments

3
    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;        

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.