How to give Read/Write permissions to a Folder during installation using .NET

后端 未结 9 1540
不思量自难忘°
不思量自难忘° 2020-11-27 14:33

I have a Setup project that I have build using Visual Studio 2010.

The installer works fine in terms of installing the application and all its dependencies into thei

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 15:20

    I stumbled also into filesystem permissions while trying to write into SQLite database after application was installed.

    As mentioned in this thread, data files can be placed into user's AppData-folder instead of modifying permissions in Program Files and such. AppData also has user permissions set to allow writing as default.

    In Setup project, this is done by adding "User's Application Data Folder" into setup File System, under which application folder can be created. Database file is then added into this application folder. Application folder with database file will be created during setup inside AppData-folder.

    Code for creating a database connection string pointing to AppData-folder is as follows:

    public static Environment.SpecialFolder DataPath = Environment.SpecialFolder.ApplicationData;
    public static string ConnectionString = "Data Source=" + Environment.GetFolderPath(DataPath) + "\\ApplicationName\\database.SQLite";
    

    I used this solution with Visual Studio 2019.

提交回复
热议问题