-1

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?

PhilDW
  • 20,260
  • 1
  • 18
  • 28
jhorwood28
  • 19
  • 6

1 Answers1

0

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:

  1. Why make the user choose a folder and complicate the setup with stuff to tell the app where it is?

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

PhilDW
  • 20,260
  • 1
  • 18
  • 28