C#从当前目录加载一个XML文件?(C# Loading a xml file from the current directory?)

编程入门 行业动态 更新时间:2024-10-09 10:22:02
C#从当前目录加载一个XML文件?(C# Loading a xml file from the current directory?)

我在我的C#winform应用程序中使用下面的代码行,这很好,但偶尔如果程序正在从命令行运行,则会出现无法找到config.xml文件的错误。 这是因为“工作目录”不同(我认为),我需要说“从当前目录加载config.xml”,我该怎么做?

docXML.Load("config.xml");

谢谢乔纳森

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

最满意答案

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

更多推荐

本文发布于:2023-08-07 12:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464155.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   文件   目录   XML   Loading

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!