1

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Josh G
  • 14,068
  • 7
  • 62
  • 74

2 Answers2

1

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 teh assembly, but this is overkill in my mind.

For the ProgramData dir, 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.

Mike Ohlsen
  • 1,900
  • 12
  • 21
0

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")
Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • This would work inside of a custom installer action, but I need to get at this data from the installed application itself. – Josh G Jun 20 '11 at 13:56
  • 1
    @Josh G: Then in that case, either hard-code them somewhere, or do some string manipulation based on physical location of the executing assembly to get the data you need, along with any other parts you may require such as expanding environment variables. But please update your question, as right now it implies you wish to do this at installation, via the installer. – Grant Thomas Jun 20 '11 at 14:00