How to read file (Metro/WinRT) How to read file (Metro/WinRT) wpf wpf

How to read file (Metro/WinRT)


This web page might be helpful: http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html

Relevant code:

public string CurrentFileBuffer{    get; private set;}public async void ReadTextFile(string Path){    var folder = Package.Current.InstalledLocation;    var file = await folder.GetFileAsync(Path);    var read = await FileIO.ReadTextAsync(file);    CurrentFileBuffer = read;}


Windows.Storage.FileIO has a bunch of helper/utility methods that do the job in a single line of code rather than using StorageIO interfaces and classes.

e.g.

ReadLineAsync()ReadTextAsync()WriteLineAsync()WriteTextAsync()


You can get your file by using this:

StorageFile file3 = await StorageFile.GetFileFromPathAsync(@"C:\myFile.txt");