.netinstallationapp-data

Get Manufacturer Name from Setup


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?


Solution

  • 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.