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

后端 未结 3 561
陌清茗
陌清茗 2020-12-31 04:19

I have been using ApplicationDeployment.CurrentDeployment.DataDirectory to store content downloaded by the client at runtime which is expected to be there every

相关标签:
3条回答
  • 2020-12-31 04:44

    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.

    0 讨论(0)
  • 2020-12-31 04:51

    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

    0 讨论(0)
  • 2020-12-31 04:54

    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

    0 讨论(0)
提交回复
热议问题