async void OnFileOpenButtonClick(object sender, RoutedEventArgs args) {
FileOpenPicker picker = new FileOpenPicker();
picker.FileTypeFilter.Add(".txt");
StorageFile storageFile = await picker.PickSingleFileAsync();
// If user presses Cancel, result is null
if (storageFile == null)
return;
Exception exception = null;
try {
using (IRandomAccessStream stream = await storageFile.OpenReadAsync()) {
using (DataReader dataReader = new DataReader(stream)) {
uint length = (uint)stream.Size;
await dataReader.LoadAsync(length);
txtbox.Text = dataReader.ReadString(length);
}
}
}
catch (Exception exc) {
exception = exc;
}
if (exception != null) {
MessageDialog msgdlg = new MessageDialog(exception.Message, "File Read Error");
await msgdlg.ShowAsync();
}
}