NoobieNeedHelp
NoobieNeedHelp

Reputation: 85

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;       

Upvotes: 1

Views: 139

Answers (2)

Algamest
Algamest

Reputation: 1529

I can confirm Damith's answer, and should be marked as so.

If you're wondering about reading the lines back in:

IsolatedStorageFileStream stream = new IsolatedStorageFileStream("SaveFolder", FileMode.Open, store);

StreamReader reader = new StreamReader(stream);

string rdr = reader.ReadLine();

rdr will be a string representing the first line, you can then call ReadLine() again to get the next line, etc. The first call to ReadLine() will return the first line you wrote to the store.

Hope this is useful to you or anyone else working in this area.

Upvotes: 1

Damith
Damith

Reputation: 63075

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"));

Upvotes: 2

Related Questions