C# IsolatedStorage Not Working

Posted by Don on Stack Overflow See other posts from Stack Overflow or by Don
Published on 2011-03-05T22:21:50Z Indexed on 2011/03/06 0:10 UTC
Read the original article Hit count: 600

Filed under:
|
|
|

I am building a C# .NET (VS2010) IE8 add-on application but am having some trouble saving data using IsolatedStorage.

No exceptions occur but, after writing the data, when I try to read the contents back it is blank, and I can find no evidence that it actually saved.

Could anyone point out any problems with the following code please that would explain why it doesn't work?

//Write
IsolatedStorageFile app_isoStore = IsolatedStorageFile.GetStore(
    IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(
    "app_started.txt", FileMode.OpenOrCreate, FileAccess.Write, app_isoStore);

StreamWriter iswriter = new StreamWriter(isoStream);
iswriter.WriteLine("Run");
iswriter.Close();

//app_isoStore.Dispose();
app_isoStore.Close();

//Read
IsolatedStorageFile app_isoStoreCheck = IsolatedStorageFile.GetStore(
    IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
IsolatedStorageFileStream isoReadStream = new IsolatedStorageFileStream(
    "app_started.txt", FileMode.Open, FileAccess.Read, app_isoStoreCheck);

StreamReader isreader = new StreamReader(isoReadStream);
string rdata = isreader.ReadToEnd();
isreader.Close();

//app_isoStoreCheck.Dispose();
app_isoStoreCheck.Close();

Should I be using:

IsolatedStorageFile.GetStore(IsolatedStorageScope.User|
    IsolatedStorageScope.Domain|IsolatedStorageScope.Assembly, null,null)

instead of:

IsolatedStorageFile.GetStore(IsolatedStorageScope.User| 
    IsolatedStorageScope.Assembly, null, null)

What's the difference between the two GetStore examples above please?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET