Guest User

Untitled

a guest
Dec 11th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. private async void BtnuploadFile_ClickAsync(object sender, RoutedEventArgs e)
  2. {
  3. FileOpenPicker openPicker = new FileOpenPicker();
  4. openPicker.ViewMode = PickerViewMode.Thumbnail;
  5. openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
  6. openPicker.FileTypeFilter.Add(".jpg");
  7. openPicker.FileTypeFilter.Add(".mp4");
  8.  
  9. file = await openPicker.PickSingleFileAsync();
  10. if (file != null)
  11. {
  12. try {
  13.  
  14. StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
  15.  
  16. StorageFolder appFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("SubFolder", Windows.Storage.CreationCollisionOption.OpenIfExists);
  17. string folderName = System.IO.Path.GetFileNameWithoutExtension(file.Name); //folder name with filename
  18. string desiredFolderNm = string.Empty;
  19. try
  20. {
  21. desiredFolderNm = folderName;
  22. //show here messagebox that is exists
  23. Windows.UI.Xaml.Controls.ContentDialog replacePromptDialog = new Windows.UI.Xaml.Controls.ContentDialog()
  24. {
  25. Title = "Upload Video",
  26. Content = "Do you want to upload file?",
  27. CloseButtonText = "No",
  28. PrimaryButtonText = "Yes"
  29. };
  30. Windows.UI.Xaml.Controls.ContentDialogResult result = await replacePromptDialog.ShowAsync();
  31. if (result == Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
  32. {
  33.  
  34. StorageFolder newFolder = await appFolder.CreateFolderAsync(desiredFolderNm, CreationCollisionOption.OpenIfExists);
  35. string desiredName = file.Name;
  36. try
  37. {
  38. progress.IsActive = true;
  39. this.IsEnabled = false;//disable UI
  40. await file.CopyAsync(newFolder, desiredName, NameCollisionOption.FailIfExists);
  41. progress.IsActive = false;
  42. this.IsEnabled =true;//disable UI
  43. var dialog = new MessageDialog("Upload Successfull");
  44.  
  45. await dialog.ShowAsync();
  46. }
  47. catch (Exception exp)
  48. {
  49. //show here messagebox that is exists
  50. Windows.UI.Xaml.Controls.ContentDialog replacePromptDialog2 = new Windows.UI.Xaml.Controls.ContentDialog()
  51. {
  52. Title = "File exists in the new location",
  53. Content = "Do you want to replace the old file with the new file?",
  54. CloseButtonText = "Keep the old one",
  55. PrimaryButtonText = "Replace with new one"
  56. };
  57. Windows.UI.Xaml.Controls.ContentDialogResult result2 = await replacePromptDialog2.ShowAsync();
  58. if (result2 == Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
  59. {
  60. await file.CopyAsync(newFolder, desiredName, NameCollisionOption.ReplaceExisting);
  61. }
  62. }
  63. }
  64.  
  65. }
  66. catch (Exception ex)
  67. {
  68. string exx = ex.ToString();
  69. var dialog = new MessageDialog(exx);
  70. await dialog.ShowAsync();
  71. }
  72.  
  73. }
  74. catch(Exception ex)
  75. {
  76. string exx = ex.ToString();
  77. var dialog = new MessageDialog(exx);
  78. await dialog.ShowAsync();
  79. }
  80. }
  81.  
  82. }
Add Comment
Please, Sign In to add comment