Drag and drop to Desktop / Explorer

DragDrop.DoDragDrop can do this as long as you pass it an appropriate DataObject.

First copy the files somewhere. You can use System.IO.Path.GetTempPath() if you don’t have anywhere better.

Next create a string array containing the full paths to the files and do the following:

string[] paths = ...;
DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, paths),
                    DragDropEffects.Copy); 

It is actually possible to do this without pre-copying the files but that gets into some complicated IDataObject interactions, so unless your files are potentially very large and aren’t already in the filesystem I would try this method first.

Leave a Comment