2

我需要像这样的路径。

"C:\Projects\ProjectName\ConfigFiles\filename.txt"

它适用于 Windows 应用程序。安装此应用程序后,我需要从安装路径访问“filename.txt”。

我尝试了很多代码,例如

Assembly.GetExecutingAssembly().Location
System.IO.Directory.GetCurrentDirectory()
etc...

这些所有代码都返回“C:\Project\ProjectName\bin\Debug”路径。请帮忙。

提前致谢。

4

2 回答 2

1

你可以简单地使用这段代码,假设你有一个filename.txt放在目录ConfigFiles中。

var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConfigFiles", "filename.txt");
于 2012-10-08T04:43:53.927 回答
-1

I think there is no build in way to get the installation path of your application. Your installer could write the path to the registry or an environment variable and your program could get it from there. In the case of an environment variable you gould use Environment.GetEnvironmentVariable

于 2012-10-08T04:26:29.827 回答