User Tools

Site Tools


notes:uwp:appdata

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
notes:uwp:appdata [2018/04/19]
leszek [Reading from Files]
notes:uwp:appdata [2018/04/19] (current)
leszek [Reading from Files]
Line 332: Line 332:
 </​code>​ </​code>​
  
 +<code csharp>
 +using Windows.Storage;​
 +using Windows.Storage.Streams;​ // for DataReader
 +...
 +// Open the file for reading. ​
 +// StorageFile.OpenReadAsync returns IAsyncOperation<​IRandomAccessStreamWithContentType>​.
 +using (IRandomAccessStream stream = await file.OpenReadAsync())
 +{
 +    // Attach the stream to a DataReader for reading.
 +    using (DataReader reader = new DataReader(stream))
 +    {
 +        uint num = (uint)stream.Size;​
 +
 +        // Load the number of bytes '​num'​ from a disk to a buffer (of type IBuffer).
 +        await reader.LoadAsync(num);​
 +
 +        // Read the bytes from the buffer as a string.
 +        string str = reader.ReadString(num);​
 +    }
 +}
 +</​code>​
  
 Read binary data from a file using a .NET class //​System.IO.BinaryReader//​ and the extension method //​AsStreamForRead//:​ Read binary data from a file using a .NET class //​System.IO.BinaryReader//​ and the extension method //​AsStreamForRead//:​
notes/uwp/appdata.txt ยท Last modified: 2018/04/19 by leszek