Reputation: 14256
In .NET, when creating a setup project the application files are stored in a path similar to this:
C:\Program Files\[Manufacturer]\[Product Name]
I am generating a folder inside of the common application data so I can read/write on Win 7 without admin privileges, so I also generated a folder at this path:
C:\ProgramData\[Manufacturer]\[Product Name]
What's the best way to get this path in code so I can read/write to this folder?
I could just put the manufacturer name in a constant string and keep it in sync. Or I could add it to the assembly manifest of one of the projects. Or I could try to save it out to file during the setup?
Any suggestions?
Upvotes: 1
Views: 283
Reputation: 1900
I don't think I would do anything in setup other than create the directory. Let the application manage getting to the directory at runtime.
I would save your Manufacturer and Product Name in a config file or a hard coded constant in your code. You could also do some kind of reflection to look it up from the assembly, but this is overkill in my mind.
For the ProgramData
directory, use the %ALLUSERSPROFILE%
environment variable to get the location. That way it would work across all versions of windows.
Then concatenate the environment variable and manufacturer / product name to build the entire directory.
Upvotes: 1
Reputation: 45083
You'll likely want to look into the Context
of the installer instance, to store the path and later find it within the Parameters
.
You will need to set the value CustomActionData
to the appropriate path (such as /TargetDir="[TARGETDIR]"
, or any other such variables that are available and desired.)
Then, in code, and as required, grab the path from the Parameters
property of the the Context
, as mentioned above:
var path Context.Parameters.Item("TargetDir")
Upvotes: 0