Where can I safely store data files for a ClickOnce deployment?

谁说胖子不能爱 提交于 2019-11-28 09:06:26

Another option is to make a directory for your application in the user's AppData folder and store it there. You can get a path to that with this:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

You'll find a lot of applications use that (and it's local equivalent). It also doesn't move around between ClickOnce versions.

Leonard Brünings

Check out IsolatedStorage this should help. It even works in partial trust environments.

To keep you data you need to use the application scoped IsolatedStorage

using System.IO;
using System.IO.IsolatedStorage;
...

IsolatedStorageFile appScope = IsolatedStorageFile.GetUserStoreForApplication();    
using(IsolatedStorageFileStream fs = new IsolatedStorageFileStream("data.dat", FileMode.OpenOrCreate, appScope))
{
...

code taken from this post

It depends on the data you are saving.

You are currently saving to the Data Directory which is fine. What you need to be aware of is that each version of the application has its own Data Directory. When you update ClickOnce copies all the data from the previous version to the new version when the application is started up. This gives you a hook to migrate any of the data from one version to the next. This is good for in memory databases like Sql Lite or SQL CE.

One thing that I cam across is that when you have a large amount of data (4 gig) if you store it in the Data Directory this data will be copied from the old version to the new version. This will slow down the start up time after an upgrade. If you have a large amount of data or you don't want to worry about migrating data you can either store the data in the users local folder providing you have full trust or you can use isolated storage if you have a partial trust.

Isolated Storage

Local User Application Data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!