Words on my addictions: .NET, Philosophy, Music

8 March 2005

Read/Write to IsolatedStorage

Filed under: C# — stefanprodan @ 3:44 pm
public void WriteIsolated(string fileName, ArrayList values) 
  { 
   //create file 
   IsolatedStorageFileStream userConfigFile = 
    new IsolatedStorageFileStream(fileName, FileMode.Create); 
   //writer 
   StreamWriter writeStream = new 
    StreamWriter(userConfigFile); 
   //write 
   for (int i = 0; i < values.Count; i++ ) 
   { 
    writeStream.WriteLine(values[i]); 
   } 
   // close all 
   writeStream.Flush(); 
   writeStream.Close(); 
   userConfigFile.Close(); 
  } 

public ArrayList ReadIsolated(string fileName) 
  { 
   ArrayList rez=new ArrayList(); 
   try 
   { 
    //open file 
    IsolatedStorageFileStream userConfigFile = 
     new IsolatedStorageFileStream(fileName, FileMode.Open); 
    //reader 
    StreamReader readStream = new 
     StreamReader(userConfigFile); 
    //read 
    string ceva = readStream.ReadLine(); 
    while(ceva!=null) 
    { 
     rez.Add(ceva); 
     ceva = readStream.ReadLine(); 
    } 
    // close all 
    readStream.Close(); 
    userConfigFile.Close(); 
   } 
   catch (System.IO.FileNotFoundException ex) 
   { 
    throw ex; 
   } 
   return rez; 
  }

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: