Matthias Shapiro

I need fewer hobbies

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

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.

One Response to Missing OpenStreamForWriteAsync on my StorageFile

  1. Pingback: Windows Store Developer Links – 2013-04-09 | Dan Rigby