简体   繁体   中英

How To Publish/Create Installer For A C# Application With An SQLite Database?

I have a simple WinForms Application written in C# using Visual Studio which includes a SQLite Database.. The Database's Build Action Property is set to “Content” and the Copy To Output Directory is set to “Copy if Newer”. The application is ready for publishing. I'd like to make an installer. What is the best way to go about this? I anticipate a few problems.. Where should I save the database file? If it gets saved into the Program Files Folder, the Database would become Read-Only.. Where should I save it and how should I go about doing so?

I will take your question as: "Where to store writable files during installation and use of application?"

There is 2 special places for this:

  1. ApplicationData special folder. This folder is accessable by current user and is actually placed in C:\\Users\\\\AppData\\Roaming (Win7). This path is stored in %APPDATA% environment variable and can be used like this:

     Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); 

    You may safely store your files in following folder structure there: %APPDATA%\\YourCompanyName\\YourAppName\\ .

  2. CommonApplicationData special folder. Almost the same as above, except it is accessable by all users and is actually placed in __ (Win7). This path is stored in %ALLUSERSPROFILE% environment variable and can be used like this:

     Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)); 

    As before, you may safely store your files in following folder structure there: %ALLUSERSPROFILE%\\YourCompanyName\\YourAppName\\ .

As for your case, here how you can get a db filepath:

var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
var dbPath = Path.Combine(appDataPath, "YourCompanyName\YourAppName", "your_db_name.sqlite3");

Real difference is: does this database are common for all windows users, or each user should have his own database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM