Home
Manage Your Code
Snippet: System.IO.IsolatedStorage (C#)
Title: System.IO.IsolatedStorage Language: C#
Description: Read and write to isolated storage Views: 337
Author: Nelson Lamprecht Date Added: 11/30/2008
Copy Code  
1private void WriteUserData()
2{
3  // create an isolated storage stream...
4  IsolatedStorageFileStream userDataFile =
5    new IsolatedStorageFileStream("UserData.dat", FileMode.Create);
6
7  // create a writer to the stream...
8  StreamWriter writeStream = new StreamWriter(userDataFile);
9
10  // write strings to the Isolated Storage file...
11  writeStream.WriteLine(string1);
12  writeStream.WriteLine(string2);
13  writeStream.WriteLine(string3);
14  writeStream.WriteLine(string4);
15  writeStream.WriteLine(string5);
16
17  // Tidy up by flushing the stream buffer and then closing
18  // the streams...
19  writeStream.Flush();
20  writeStream.Close();
21  userDataFile.Close();
22}
23
24private void ReadUserData()
25{
26  // create an isolated storage stream...
27  IsolatedStorageFileStream userDataFile =
28    new IsolatedStorageFileStream("UserData.dat", FileMode.Open);
29
30  // create a reader to the stream...
31  StreamReader readStream = new StreamReader(userDataFile);
32
33  // write strings to the Isolated Storage file...
34  string1 = readStream.ReadLine();
35  string2 = readStream.ReadLine();
36  string3 = readStream.ReadLine();
37  string4 = readStream.ReadLine();
38  string5 = readStream.ReadLine();
39
40  // Tidy up by closing the streams...
41  readStream.Close();
42  userDataFile.Close();
43}
44