Missing OpenStreamForWriteAsync on my StorageFile
I have a sample that I use when serializing data in order to save it to a StorageFile in Windows 8 and Windows Phone 8. It looks a little something (or exactly) like this:
StorageFile kittenFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("Kittens4Ever.kittens", CreationCollisionOption.ReplaceExisting);
var writeStream = await kittenFile.OpenStreamForWriteAsync();
DataContractSerializer kittenSerial = new DataContractSerializer(typeof(ObservableCollection<Kitten>));
kittenSerial.WriteObject(writeStream, listOfKittens);
await writeStream.FlushAsync();
writeStream.Close();
But I keep running into this problem where my StorageFile doesn’t have the OpenStreamForWriteAsync method available. After yelling and cursing and bing-ing the problem for a while, I realize the solution:
OpenStreamForWriterAsync (and OpenStreaForReadAsync) are extension methods that require System.IO to be added as a reference. So I just add it
using System.IO;
and everything works fine.
Comments
Anonymous
June 16, 2013
it works! thanks a lotAnonymous
October 09, 2013
Thank you so much for this! I was doing the same until I cam across your post!Anonymous
December 16, 2014
Mil gracias, fue de muchisima ayuda :)Anonymous
January 05, 2015
Thank you so much for this! I was doing the same until I cam across your post!