private async void FileErrorAttachment_Click(object sender, RoutedEventArgs e) { // Open a text file. FileOpenPicker open = new FileOpenPicker(); open.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; open.FileTypeFilter.Add("*"); // When running on win32, FileOpenPicker needs to know the top-level hwnd via IInitializeWithWindow::Initialize. if (Window.Current == null) { IInitializeWithWindow initializeWithWindowWrapper = open.As <IInitializeWithWindow>(); IntPtr hwnd = GetActiveWindow(); initializeWithWindowWrapper.Initialize(hwnd); } StorageFile file = await open.PickSingleFileAsync(); var filePath = string.Empty; if (file != null) { filePath = file.Path; FileAttachmentLabel.Text = filePath; } else { FileAttachmentLabel.Text = "The file isn't selected"; } localSettings.Values[Constants.KeyFileErrorAttachments] = filePath; }
private async Task <Tuple <string, ILanguage> > GetCodeFileText() { try { var picker = new FileOpenPicker(); IntPtr windowHandle = (App.Current as App).WindowHandle; IInitializeWithWindow initializeWithWindowWrapper = picker.As <IInitializeWithWindow>(); initializeWithWindowWrapper.Initialize(windowHandle); picker.FileTypeFilter.Add("*"); var file = await picker.PickSingleFileAsync(); if (file == null) { return(null); } System.Diagnostics.Debugger.Launch(); string text = ""; using (var reader = new StreamReader(await file.OpenStreamForReadAsync(), true)) { text = await reader.ReadToEndAsync(); } ILanguage Language = Languages.FindById(file.FileType.Replace(".", "")) ?? Languages.CSharp; return(new Tuple <string, ILanguage>(text, Language)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); return(new Tuple <string, ILanguage>("ERROR", Languages.CSharp)); } }