Monday, December 15, 2008

I spent a while working this one out and none of the google hits  showed me what I needed so I thought I'd blog it here. When you hook the Drop event how do you deal with multiple files being dropped? The GetData("FileNameW") member only returns a single file name in the string array even if multiple files are being dragged. GetData("FileName") returns a single file name in 8.3 compatible munged form so that doesn't help. I looked in the help for System.Windows.DataObject and it has a GetFileDropList member. However, it turns out that the DragDropEventArgs.Data is an IDataObject not a DataObject. So if you cast it to a DataObject you get access to the file list

if (e.Data.GetFormats().Contains("FileDrop"))
{
    DataObject dataObject = e.Data as DataObject;
    StringCollection files = null;
    if (dataObject != null)
    {
        files = dataObject.GetFileDropList();
    }
    else
    {
        // not sure if this is necessary but its defensive coding
        string[] fileArray = (string[])e.Data.GetData("FileNameW");
        files = new StringCollection();
        files.Add(fileArray[0]);
    }

    foreach (string file in files)
    {
        // process files
    }
}

Hopefully someone else looking how to do this will stumble across this blog post and save some time

 | 
Monday, December 15, 2008 8:01:53 PM (GMT Standard Time, UTC+00:00)  #    Comments [5]Trackback
Sunday, January 29, 2012 1:43:55 PM (GMT Standard Time, UTC+00:00)
That's the smart thinking we could all beinfet from.
Monday, January 30, 2012 7:20:03 AM (GMT Standard Time, UTC+00:00)
Hyzazq <a href="http://yznybiwfqqnq.com/">yznybiwfqqnq</a>
Monday, January 30, 2012 11:53:05 AM (GMT Standard Time, UTC+00:00)
ye8SA8 , [url=http://hnmvoiajjugw.com/]hnmvoiajjugw[/url], [link=http://niuxleevyann.com/]niuxleevyann[/link], http://sjchchfhvudb.com/
Wednesday, February 01, 2012 8:09:44 AM (GMT Standard Time, UTC+00:00)
ypKDrt <a href="http://pquyynqwzkid.com/">pquyynqwzkid</a>
Friday, February 03, 2012 9:47:27 AM (GMT Standard Time, UTC+00:00)
JoHqO3 , [url=http://inddutsghati.com/]inddutsghati[/url], [link=http://twhmvvxjckri.com/]twhmvvxjckri[/link], http://ppyxenrldexh.com/
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):