views:

322

answers:

3

I have a WinForms app that has a TreeView. The user can drag files from WindowsExplorer to the TreeView, and then they can drag the files back into WindowsExplorer which in affect copies the files to wherever the files were dropped. What I'm trying to do is, if the files already exist in the directory where the files are being dropped, I want to rename the files/folders being copied in ahead of time, so that there's no collision.

Here's how I'm copying files into WindowsExplorer. On the treeView's ItemDrag, I loop through the nodes of the selected node, and then package that into an array. Then, I use this code:

        var dataObject = new DataObject(DataFormats.FileDrop, files.ToArray());
        dataObject.SetData(DataFormats.StringFormat, dataObject);
        DoDragDrop(dataObject, DragDropEffects.Copy);

This works well, but once it ships off to Windows Explorer, it's out of my hands. How can I find out when and where the files are being copied TO and intercept that to make changes? Is this possible?

+1  A: 

Explorer Drag & Drop is an excellent article doing what you are trying to achieve.

EDIT2: It seems that there's a C++ article available for the same on CodeProject. But I was unable to find a way of how to do it using C#.

Kirtan
That doesn't cover the main problem I'm having. If you try to drag from the listbox in his example back into explorer, you get prompted by windows like you normally would. I want to avoid that, and automatically rename files.
BFree
A: 

i don't think that is possible.

Benny
A: 

AFAIK, there is no way to know drop target (in your case destination folder). You can look into CFSTR_FILENAMEMAP shell clipboard format, but still in this case you can only provide name mappings before (or in process) of drag-n-drop.

Also note, that default DataObject in .net has limited shell support. So if you need to use mentioned above format, you need to write your own IDataObject implementation (or take someone's implementation, good example with lot shell drag-n-drop related stuff can be found here)

arbiter