Background - I'm looking at using clickonce for deployment of a WinForms app via clickonce (via website). The elements of the relatively simply application are: - it is an executable and one database file (sqlite) - database (sqlite) will need to be updates sometimes by the application (e.g. add table, add column) - database data (which is just a file for sqlite) needs remain across upgrades of course
Assumption - I'm assuming here that the best way to allow for the above under clickone is to:
- use the Data Directory for the location of the sqlite database file
- write the smarts into the MainForm load method to:
- check whether there is a need to create a database file in the Data Directory (DD) programmatically (via ApplicationDeployment.CurrentDeployment.IsFirstRun), or if not copy the existing database file from the PRE area (where clickonce should have made a copy of it) to the main DD area
- check the version of the database file in the DD and then update it
Question - Is there any requirement for ClickOnce to have special access (Admin, or elevated priviledge) to read/write to/form the Data Directory are described above? That is can I assume the most basic user's PC should be able to do this (either a home PC, or work PC in an organisation) in general.
thanks
What i would suggest (easiest to do) is add the file(SQLLite database I believe) as an existing resource, right click it, go to properties and change build action to Content, and Copy to output directory to "Copy if newer".
From here you have 2 options:
If you won't ever change the original SQL File when updating then you can leave it as that, but if you're looking to make changes now and again, I would suggest the following:
String appPath = Path.GetDirectoryName(Application.ExecutablePath);
if (!System.IO.File.Exists(appPath + @"\Resources\SQLLite.db"))
{
System.IO.File.Copy(appPath + @"\Resources\SQLLiteIncluded.db", appPath + @"\Resources\SQLLite.db");
}
If need be, you can copy to a the current users application data folder if the program will not have write access to its executable path(most instances it does)
\Resources\ is a folder I have created in my project, (which gets copied to the executable path if there's files inside it that are content) hence why I included it in the paths. (This is optional)
Regarding the administrative rights, I don't need any administrative right for this on our network, but we deploy via network drive not a website, but I would assume it would be the same.
You specify what access things may need. For instance, the following can be added to the app.manifest:
<requestedExecutionLevel level=”requireAdministrator” uiAccess=”false” />
The best way to go about is really to test whether you actually need the administrator rights. If the application is full trust, you shouldn't have any issues in any case.
来源:https://stackoverflow.com/questions/2369025/clickonce-does-writing-reading-to-the-data-directory-required-admin-rights