private async void ImageUploadButton_OnClick(object sender, RoutedEventArgs e) { loadingProgressBar.Visibility = Visibility.Visible; var openPicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary }; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".gif"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file == null) { return; } IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); ImgurEntity result = null; try { result = await UploadManager.UploadImgur(stream); } catch (Exception) { Debug.WriteLine("Error with Imgur *SHOCK*"); } if (result == null) { var msgDlg = new MessageDialog("Something went wrong with the upload. My heart bleeds for you."); msgDlg.ShowAsync(); return; } // We have got an image up on Imgur! Time to get it into the reply box! string imgLink = string.Format("[TIMG]{0}[/TIMG]", result.data.link); ReplyText.Text = ReplyText.Text.Insert(ReplyText.Text.Length, imgLink); loadingProgressBar.Visibility = Visibility.Collapsed; }
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs fileOpenPickerContinuationEventArgs) { if (fileOpenPickerContinuationEventArgs.Files == null) { return; } var file = fileOpenPickerContinuationEventArgs.Files.First(); if (file == null) { return; } LoadingProgressBar.Visibility = Visibility.Visible; IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); ImgurEntity result = null; try { result = await UploadManager.UploadImgur(stream); } catch (Exception) { Debug.WriteLine("Error with Imgur *SHOCK*"); } if (result == null) { var msgDlg = new MessageDialog("Something went wrong with the upload. My heart bleeds for you."); msgDlg.ShowAsync(); LoadingProgressBar.Visibility = Visibility.Collapsed; return; } // We have got an image up on Imgur! Time to get it into the reply box! string imgLink = string.Format("[TIMG]{0}[/TIMG]", result.data.link); ReplyTextBox.Text = ReplyTextBox.Text.Insert(ReplyTextBox.Text.Length, imgLink); LoadingProgressBar.Visibility = Visibility.Collapsed; }