如何在app.config文件中设置相对路径?

时间:2010-02-22 06:57:22

标签: c# relative-path 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放在那里?

谢谢和问候, 谢卡尔

1 个答案:

答案 0 :(得分:2)

回答1:,请检查Path Class

answer2:将您的dll保存在项目的输出目录中。调试/发布

见下文

Optimizing Visual Studio solution build - where to put DLL files?