I have created a windows service application in C# which uses an SQLite database file to store data it receives. I want to be able to allow the user to select the directory the SQLite database file is stored on their PC during installation. How can I do this, and how can the main application obtain the file path chosen by the user?
-
Which installer do you use? – Freggar Jun 29 '18 at 07:45
-
http://wixtoolset.org/ – Simon Price Jun 29 '18 at 07:45
-
I'm currently using the setup project installer included with visual studio 2017, I have not created an installer before so this is new to me. – jhorwood28 Jun 29 '18 at 07:59
1 Answers
The only folder that Visual Studio Setups (and most others too) let you choose is the Application Folder that defaults to Program Files.
It really isn't worth doing what you ask because:
Why make the user choose a folder and complicate the setup with stuff to tell the app where it is?
What if the user chooses a folder that apps cannot access if you want to allow limited users to run the app? Or a location that makes the install fail?
It's better to just choose the most reasonable working location that you can thoroughly test with the app, and that's AppDataFolder if it's private to the app. That's User's Application Data Folder in the setup project file system view.
https://learn.microsoft.com/en-us/windows/desktop/Msi/appdatafolder
Then the app automatically knows where it is and everything just works.
VS setups don't support what you're asking, other tools do, but, again, usually setups just install files to the appropriate folders that make the app work. By the way, custom actions won't do this because all VS custom actions run after the files are installed.

- 20,260
- 1
- 18
- 28