问题描述
在VS2008中,我编写了一个c#服务,一个安装程序,并创建了一个安装程序包来进行安装.该服务需要加载一个xml文件才能运行.将此文件放在VS安装项目提供的各种文件系统文件夹中的最佳位置是什么,然后如何从代码中引用这些路径?
In VS2008 I have writen a c# service, an installer and created a setup package to install it. The service needs to load an xml file to operate. Where is the best place to put this file in the various filesystem folders offered by the VS setup project, and how do I then refer to these paths from my code?
谢谢
[我应该指出,该服务以LocalService的身份运行,这意味着即使使用了为所有用户安装",也无法访问VS安装项目中用户的应用程序数据文件夹"项提供的applicationdata文件夹.在安装过程中.我可以轻松解决这个问题,但想了解最佳做法]
[I should point out the the service runs as LocalService, which means that the applicationdata folder offered by the "User's Application Data Folder" item in the VS setup project is not accessible, even when "Install for all users" is used during installation. I could easily hack around this, but would like to understand best practice]
推荐答案
我不确定哪个位置存储XML文件更好.我认为这并不重要.但是,如果您需要在系统中获取特殊的文件夹路径,则可以使用Environment类来实现.下面的代码行获取程序文件的路径:
I am not sure which place is better to store the XML file. I don't think it will matter alot. But if you need to get special folder path in the system you can use Environment class to do so. The following line of code get the path of the Program Files:
string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
这篇关于在C#中找到安装程序路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!