Isolated Storage is a special and safe place in the computer to save user data in machine/assembly scope or user/assembly scope. It eliminates the risk of making damages to the whole system by the user, and the application will run regardless of whether it's running uder partial, limited or full trust security level.
There are two important classes for isolated storage: IsolatedStorageFile and IsolatedStorageFileStream class. The IsolatedStorageFile class is responsible for creating files and directories in isolated storage. The IsolatedStorageFileStream class inherites from FileStream and is responsible for file IO.
To read data from isolated storage:
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly();
// here we could also call IsolatedStorageFile.GetMachineStoreForAssembly() to get store for the application scope.
IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileName, FileMode.Open, store);
StreamReader rdr = new StreamReader(theFile);
string s = rdr.ReadToEnd();
To write data is similar:
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly();
// here we could also call IsolatedStorageFile.GetMachineStoreForAssembly() to get store for the application scope.
IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileName, FileMode.Create, store);
StreamWriter writer = new StreamWriter(theFile);
writer.WriteLine("hello");
Sunday, 19 November 2006
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment