2

How i can save a Stream to File in WinRT. Currently i am working on a Open Source library for creating PDF file in windows 8. I build the stream with pdf content, now my requirement is to save this stream to file. Can anyone please guide me to solve this issue.

Stephan Ronald
  • 1,395
  • 2
  • 14
  • 39

1 Answers1

2

I assume you're working with C#? One way to do it would be to read the stream content using DataReader and store it into a byte[] buffer. After that you can create the file like this:

var file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("filename", Windows.Storage.CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteBytesAsync(file, buffer);

Then again, if you already have to byte data for the pdf, you can skip making it a stream in the first place.

Hope this helped.

Scott Ferguson
  • 7,690
  • 7
  • 41
  • 64
Muhwu
  • 1,151
  • 1
  • 10
  • 26
  • Same question but with an emphasis on 'streams'. I want to serialize some data that I write to a user file. When the user starts up the application, the state of the data model is read from this file. How do I connect these isolated storage objects to the library of stream functions? – Quark Soup Dec 08 '16 at 16:07