private void cmnuRename_Click(object sender, EventArgs e) { ApplicationJob job = olvJobs.SelectedObject as ApplicationJob; if (string.IsNullOrEmpty(job.CurrentLocation)) { return; } using (RenameFileDialog dialog = new RenameFileDialog()) { dialog.FileName = job.PreviousLocation; if (dialog.ShowDialog(this) == DialogResult.OK) { try { File.Move(job.CurrentLocation, dialog.FileName); job.PreviousLocation = dialog.FileName; job.Save(); } catch (FileNotFoundException) { MessageBox.Show(this, "The file to be renamed does not exist anymore.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private async Task <string> GetNewName(string currentName) { RenameFileDialog dialog = new RenameFileDialog(currentName); await dialog.ShowAsync(); return(dialog.Result); }
private async void OnRename(object parameter) { bool NameAlreadyExist = false; while (true) { if (fileList.SelectedItems.Count == 1) { FileItem item = fileList.SelectedItems[0] as FileItem; RenameFileDialog rename = new RenameFileDialog(); if (NameAlreadyExist) { rename.FileExist = Windows.UI.Xaml.Visibility.Visible; } else { rename.FileExist = Windows.UI.Xaml.Visibility.Collapsed; } rename.NewFileName = item.Name; DialogResult result = await ShowDialog(rename); if (string.IsNullOrEmpty(rename.NewFileName) || rename.NewFileName == item.Name) { return; } switch (result) { case DialogResult.No: return; case DialogResult.Cancel: return; } StorageFolder mindlocation = ApplicationData.Current.RoamingFolder; if (!string.IsNullOrEmpty(SubFolder)) { mindlocation = await mindlocation.GetFolderAsync(SubFolder); } StorageFile file = await mindlocation.GetFileAsync(item.Name + ".xml"); try { await file.RenameAsync(rename.NewFileName + ".xml"); } catch { NameAlreadyExist = true; continue; } item.Name = rename.NewFileName; return; } } }