ClickOnce and IsolatedStorage
Asked Answered
L

4

10

The Winform application is release with ClickOnce in our Intranet. We store personal preference for the GUI in the Isolated Storage. All works pretty fine :)

The problem is when we have a new version of the application, we publish... all preferences are lost! User need to setup their preference over and over each version.

Is there a way to freeze the isolation for the whole application instead of the version?

Lunula answered 14/10, 2008 at 17:8 Comment(0)
A
19

You need to use application scoped, rather than domain scoped, isolated storage. This can be done by using one of IsolatedStorageFileStream's overloaded constructors.

Example:

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

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

However, now you will run into the issue of this code only working when the application has been launched via ClickOnce because that's the only time application scoped isolated storage is available. If you don't launch via ClickOnce (such as through Visual Studio), GetUserStoreForApplication() will throw an exception.

The way around this problem is to make sure AppDomain.CurrentDomain.ActivationContext is not null before trying to use application scoped isolated storage.

Aquifer answered 22/10, 2008 at 19:32 Comment(4)
I will try that. Seem to be the best answer yet.Lunula
I am running inside VS and it doesnt raise any error. I accept your answer without testing it yet with the real deployement. I'll write back here if it doesn't work. ThxLunula
or you can use System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed to know if the app was deployed with ClickOnce and you can use GetUserStoreForApplication()Tragedy
any full source code sample? sample using "IsolatedStorageFileStream fs" variable?Exocarp
A
4

I was working on a ClickOnce app a while ago and used Environment.GetFolderPath(ApplicationData) - e.g. roaming app data folder, to store all settings. Worked fine and survived numerous updates. Just create a subdireectory with the name of your app or CompanyName/AppName or whatever and store everything in there.

Affined answered 14/10, 2008 at 17:25 Comment(0)
A
2

a summary from the other answers:

IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForAssembly();//for visual studio
if (System.Deployment.Application.ApplicationDeployment.IsNetwor‌​kDeployed)
{
    isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();//for click once applications
}
Airliah answered 7/12, 2017 at 11:34 Comment(0)
D
1

You have to store a permanent version of user settings in a more durable store like database. Your application can decide to use the isolated storage if it is available. If it is not available (because of a newer version), the app should get the settings from database and use it to re-initialize the settings in isolated storage. If settings are changed, you should update both places. Unless there is a newer version of the app, your app should not have to get the settings from DB.

Diestock answered 14/10, 2008 at 17:12 Comment(2)
That was mi initial idea, but I was interesting to know if they were a work around :PLunula
You can store the settings file in a specific location on the user's hard drive but you will have to make the app full-trust..Diestock

© 2022 - 2024 — McMap. All rights reserved.