private async void OnExport(object parameter) { DialogResult result = DialogResult.None; bool repeatResult = false; //if (EnsureUnsnapped()) { FolderPicker exportDialog = new FolderPicker(); exportDialog.CommitButtonText = "Export"; exportDialog.FileTypeFilter.Add(".xml"); StorageFolder targetFolder = await exportDialog.PickSingleFolderAsync(); if (targetFolder != null) { foreach (FileItem item in fileList.SelectedItems) { StorageFolder mindlocation = ApplicationData.Current.RoamingFolder; if (!string.IsNullOrEmpty(SubFolder)) { mindlocation = await mindlocation.GetFolderAsync(SubFolder); } StorageFile file = await mindlocation.GetFileAsync(item.Name + ".xml"); bool fileExist = false; StorageFile newFile = null; var fs = await targetFolder.GetFilesAsync(); foreach (var f in fs) { if (f.Name == file.Name) { newFile = f; fileExist = true; } } if (fileExist) { if (!repeatResult) { ReplaceFilesDialog replaceDialog = new ReplaceFilesDialog(); replaceDialog.FileName = " " + item.Name + ".xml"; result = await ShowDialog(replaceDialog); repeatResult = replaceDialog.Repeat; } switch (result) { case DialogResult.Cancel: return; case DialogResult.No: continue; case DialogResult.Yes: await file.CopyAndReplaceAsync(newFile); break; } } else { newFile = await file.CopyAsync(targetFolder, file.Name); } } } } }
private async void OnImport(object parameter) { DialogResult result = DialogResult.None; bool repeatResult = false; //if (EnsureUnsnapped()) { FileOpenPicker fileDialog = new FileOpenPicker(); fileDialog.CommitButtonText = "Import"; fileDialog.FileTypeFilter.Add(".xml"); var files = await fileDialog.PickMultipleFilesAsync(); if (files != null) { foreach (var file in files) { StorageFolder installedLocation = ApplicationData.Current.RoamingFolder; if (!string.IsNullOrEmpty(SubFolder)) { installedLocation = await installedLocation.GetFolderAsync(SubFolder); } bool fileExist = false; StorageFile newFile = null; var fs = await installedLocation.GetFilesAsync(); foreach (var f in fs) { if (f.Name == file.Name) { newFile = f; fileExist = true; } } if (fileExist) { if (!repeatResult) { ReplaceFilesDialog replaceDialog = new ReplaceFilesDialog(); replaceDialog.FileName = " " + file.Name + ".xml"; result = await ShowDialog(replaceDialog); repeatResult = replaceDialog.Repeat; } switch (result) { case DialogResult.Cancel: return; case DialogResult.No: continue; case DialogResult.Yes: await file.CopyAndReplaceAsync(newFile); break; } } else { newFile = await file.CopyAsync(installedLocation, file.Name); ObservableCollection <FileItem> items = fileList.DataContext as ObservableCollection <FileItem>; items.Add(new FileItem() { Name = newFile.DisplayName, Load = this.Load }); } } } } }