开发者

C# Loading a xml file from the current directory?

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 th开发者_StackOverflowis?

docXML.Load("config.xml");

Thanks Jonathan


string fileName = Path.Combine(Application.StartupPath, "config.xml");


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜