I get the following on the second using(StreamWriter statement:
Value does not fall within the expected range.
#region save allowance
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
//Open existing file
IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("foo.txt", FileMode.Truncate, FileAccess.Write);
using (StreamWriter writer = new StreamWriter(fileStream))
{
writer.Write(App.ViewModel.Foo);
}
#endregion
#region save log
IsolatedStorageFileStream fileStream2 = myIsolatedStorage.OpenFile("log.txt", FileMode.Truncate, FileAccess.Write);
using (StreamWriter writer = new StreamWriter(fileStream))
{
foreach( var i in App.ViewModel.Items )
writer.Write(i.ToString());
}
#endregion
You’re reusing fileStream the second time instead of fileStream2. By the way, to avoid this kind of mistake, you may want to wrap your filestream inside the using block.