如何在app.config文件中设置相对路径?
我正在开发一个项目,其中有许多文本和 xml 文件。我在运行时从程序中读取这些内容。
我已将这些文件的路径保留在 app.config 文件中,但所有路径都是绝对路径,例如 "C:\my_project\help_files\rejectList.txt" 。
如果我只保留“\help_files\rejectList.txt”路径,程序会抛出 filenotfound 异常。
Can anyone please tell me how to set relative paths in C# applications?
我想设置类似“$root\help_files\rejectList.txt”的内容,并且在运行时 $root 应解析为实际路径。
Is there any way in .net to set paths like this?
另外,我还有一个问题。我的项目也需要一些 dll。人们通常将 dll 保存在哪里?与 exe 文件位于同一文件夹中,还是应该创建一个名为“lib”的文件夹并将 dll 放在那里?
谢谢和问候, 谢卡尔
I am working on a project in which I have many text and xml files. I read those from my program at runtime.
I have kept paths to those files in app.config file, but all the paths are absolute paths like "C:\my_project\help_files\rejectList.txt" .
If I keep only "\help_files\rejectList.txt" path, program throws filenotfound exception.
Can anyone please tell me how to set relative paths in C# applications?
I would like to set something like "$root\help_files\rejectList.txt" and at runtime $root should resolve to actual path.
Is there any way in .net to set paths like this?
Also, I have one more question. I have some dll's also that are needed for my project. Where do people usually keep dll's? In same folder as that of the exe file or should we create one folder called "lib" and put dll's there?
Thanks and Regards,
Shekhar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案 1:,检查路径类
答案2:将您的dll保留在项目的输出目录中。调试/发布
请参见下文
优化 Visual Studio 解决方案构建 - 在哪里放置 DLL 文件?
answer 1:, check Path Class
answer2: keep your dll's in output directory of projects. debug / release
see below
Optimizing Visual Studio solution build - where to put DLL files?