I want to create a file, save data and then append some information to it (ex. the next time app will be started). I’m using this code:
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
using (var isoFileStream = new IsolatedStorageFileStream("history.dat", FileMode.Append, FileAccess.Write, myStore))
{
//Write the data
using (var isoFileWriter = new StreamWriter(isoFileStream))
{
isoFileWriter.WriteLine(m.Author + "|" + m.Receiver + "|" + m.Text + "|" + m.Date + "\r\n");
}
}
But it doesn’t work :/ Only first line is saved – anything I want to add to the created file is going to nowhere o_O I also tried this approach:
using (var isoFileStream = new IsolatedStorageFileStream("history.dat", FileMode.Open, myStore))
{
// Read the data.
using (var isoFileReader = new StreamReader(isoFileStream))
{
data = isoFileReader.ReadLine();
}
}
To verify the file I have used another class and IsoStoreSpy application.
Please help.
Appending works fine using your code. But for reading all lines you have to iterate them, otherwise you read just the first line:
Tested and works. And you don’t need to append the new line (“\r\n”) when writing a line.
WriteLinewill do this for you.