Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private async void BtnuploadFile_ClickAsync(object sender, RoutedEventArgs e)
- {
- FileOpenPicker openPicker = new FileOpenPicker();
- openPicker.ViewMode = PickerViewMode.Thumbnail;
- openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
- openPicker.FileTypeFilter.Add(".jpg");
- openPicker.FileTypeFilter.Add(".mp4");
- file = await openPicker.PickSingleFileAsync();
- if (file != null)
- {
- try {
- StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
- StorageFolder appFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("SubFolder", Windows.Storage.CreationCollisionOption.OpenIfExists);
- string folderName = System.IO.Path.GetFileNameWithoutExtension(file.Name); //folder name with filename
- string desiredFolderNm = string.Empty;
- try
- {
- desiredFolderNm = folderName;
- //show here messagebox that is exists
- Windows.UI.Xaml.Controls.ContentDialog replacePromptDialog = new Windows.UI.Xaml.Controls.ContentDialog()
- {
- Title = "Upload Video",
- Content = "Do you want to upload file?",
- CloseButtonText = "No",
- PrimaryButtonText = "Yes"
- };
- Windows.UI.Xaml.Controls.ContentDialogResult result = await replacePromptDialog.ShowAsync();
- if (result == Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
- {
- StorageFolder newFolder = await appFolder.CreateFolderAsync(desiredFolderNm, CreationCollisionOption.OpenIfExists);
- string desiredName = file.Name;
- try
- {
- progress.IsActive = true;
- this.IsEnabled = false;//disable UI
- await file.CopyAsync(newFolder, desiredName, NameCollisionOption.FailIfExists);
- progress.IsActive = false;
- this.IsEnabled =true;//disable UI
- var dialog = new MessageDialog("Upload Successfull");
- await dialog.ShowAsync();
- }
- catch (Exception exp)
- {
- //show here messagebox that is exists
- Windows.UI.Xaml.Controls.ContentDialog replacePromptDialog2 = new Windows.UI.Xaml.Controls.ContentDialog()
- {
- Title = "File exists in the new location",
- Content = "Do you want to replace the old file with the new file?",
- CloseButtonText = "Keep the old one",
- PrimaryButtonText = "Replace with new one"
- };
- Windows.UI.Xaml.Controls.ContentDialogResult result2 = await replacePromptDialog2.ShowAsync();
- if (result2 == Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
- {
- await file.CopyAsync(newFolder, desiredName, NameCollisionOption.ReplaceExisting);
- }
- }
- }
- }
- catch (Exception ex)
- {
- string exx = ex.ToString();
- var dialog = new MessageDialog(exx);
- await dialog.ShowAsync();
- }
- }
- catch(Exception ex)
- {
- string exx = ex.ToString();
- var dialog = new MessageDialog(exx);
- await dialog.ShowAsync();
- }
- }
- }
Add Comment
Please, Sign In to add comment