JamBaseShellListViewBeforeShellDrop Event |
Namespace: Jam.Shell
using Jam.Shell; using System.IO; private PathCollection m_DroppedFiles; private void shellListView1_BeforeShellDrop(object sender, BeforeShellDropEventArgs e) { // maybe clear if old dropped files are present if (m_DroppedFiles != null) m_DroppedFiles.Clear(); /* // If you don`t want the ShellDrop to be executed, just set the flag to false if (...) { e.ExecuteShellDrop = false; return; } */ /* - possibility to watch what is dropped for (int i = 0; i < e.Files.Count; i++) { MessageBox.Show(e.Files[i]); }*/ // save the dropped files // here you could filter the files that should later be renamed m_DroppedFiles = e.Files; } private void shellListView1_OperationPerformed(object sender, OperationEventArgs e) { if (e.Operation == ShellOperation.Drop) { // fill a new PathCollection, because the AffectedObjects will change during the rename process PathCollection localDroppedFiles = new PathCollection(e.AffectedObjects); // use a temporary ShellBrowser instance using (ShellBrowser sb = new ShellBrowser()) { // set the ShellBrowser folder to the drop destination sb.Folder = e.Destination; foreach (string objectPath in localDroppedFiles) { // if the affected object can be found in our list, rename it if (m_DroppedFiles != null && m_DroppedFiles.Contains(objectPath)) { // set the objectname to the filename of the dropped file sb.ObjectName = Path.GetFileName(objectPath); // delete it from the list m_DroppedFiles.Delete(m_DroppedFiles.IndexOf(objectPath)); // rename sb.RenameObject("MyNewFileName.txt"); // show the new name //MessageBox.Show(sb.ObjectName); } } } } }