Пример #1
0
        private void OnRename(object sender, RoutedEventArgs e)
        {
            var selectedPhoto = PictureBox.SelectedItem as Photo;

            if (selectedPhoto != null)
            {
                var filename = selectedPhoto.FullPath;
                var dialog   = new RenameDialog(Path.GetFileNameWithoutExtension(filename));
                if (dialog.ShowDialog() == true) // Result could be true, false, or null
                {
                    try
                    {
                        var directoryName = Path.GetDirectoryName(filename);
                        if (directoryName != null)
                        {
                            File.Move(filename,
                                      string.Format("{0}{1}", Path.Combine(directoryName, dialog.NewFilename),
                                                    Path.GetExtension(filename)));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Cannot Rename File", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
Пример #2
0
        void renameMenu_Click(object sender, RoutedEventArgs e)
        {
            RenameDialog dialog = new RenameDialog(Path.GetFileNameWithoutExtension(filename));

            if (dialog.ShowDialog() == true) // Result could be true, false, or null
            {
                // Attempt to rename the file
                try
                {
                    File.Move(filename, Path.Combine(Path.GetDirectoryName(filename), dialog.NewFilename) + Path.GetExtension(filename));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Cannot Rename File", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Пример #3
0
 void renameMenu_Click(object sender, RoutedEventArgs e)
 {
     string filename = (pictureBox.SelectedItem as ListBoxItem).Tag as string;
     RenameDialog dialog = new RenameDialog(Path.GetFileNameWithoutExtension(filename));
     if (dialog.ShowDialog() == true) // Result could be true, false, or null
     {
         // Attempt to rename the file
         try
         {
             File.Move(filename, Path.Combine(Path.GetDirectoryName(filename), dialog.NewFilename) + Path.GetExtension(filename));
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Cannot Rename File", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }