views:

456

answers:

2

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?

Thanks

[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]

+3  A: 

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);
mnour
OK, simple example. Installer creates folder %program files%\mycompany\myapp , but this is subject to change should the person installing change the installation path. So, for instance, how can I get to the install folder? The code in this example only goes as far as ProgramFiles.
spender
Are you looking for the folder in which myapp has been installed? How about just looking in the directory where your assembly resides? I.e. Assembly.GetExecutingAssembly().Location?
OregonGhost
A: 

You could always use the registry.

DylanJ