Search code examples
c#isolatedstorage

Storing more than one value into Isolated Storage


I have created a isolated storage that only store one values and display one value of e.g. "aaaaaaaa,aaaaaaaa".
How can I make it so that it stores
1)"aaaaaaaa,aaaaaaaaa"
2)"bbbbbbbb,bbbbbbbbb"
3)"cccccccccc,cccccccccc"

Below shows codes that stores only one value:

//get the storage for your app 
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
//define a StreamWriter
StreamWriter writeFile;

if (!store.DirectoryExists("SaveFolder"))
{
    //Create a directory folder
    store.CreateDirectory("SaveFolder");
    //Create a new file and use a StreamWriter to the store a new file in 
    //the directory we just created
    writeFile = new StreamWriter(new IsolatedStorageFileStream(
         "SaveFolder\\SavedFile.txt", 
         FileMode.CreateNew, 
         store));
}
else
{
    //Create a new file and use a StreamWriter to the store a new file in 
    //the directory we just created
    writeFile = new StreamWriter(new IsolatedStorageFileStream(
         "SaveFolder\\SavedFile.txt", 
         FileMode.Append, 
         store));
}

StringWriter str = new StringWriter();
str.Write(textBox1.Text);
str.Write(",");
str.Write(textBox2.Text);

writeFile.WriteLine(str.ToString());
writeFile.Close();

textBox1.Text = string.Empty;
textBox2.Text = string.Empty;

    StringWriter str = new StringWriter();
str.Write(textBox1.Text);
str.Write(",");
str.Write(textBox2.Text);


writeFile.WriteLine(str.ToString());
writeFile.Close();

textBox1.Text = string.Empty;
textBox2.Text = string.Empty;       

Solution

  • You can use WriteLine several times like below

    writeFile.WriteLine(string.Format("{0},{1}", "aaaaa","aaaaa"));
    writeFile.WriteLine(string.Format("{0},{1}", "bbbbb","bbbbb"));
    writeFile.WriteLine(string.Format("{0},{1}", "ccccc","ccccc"));