DataFormats.FileDrop Problem when dropping from explorer
From: MikeWorkflow (MikeWorkflow_at_discussions.microsoft.com)
Date: Mon, 20 Dec 2004 10:45:05 -0800
I've run into a problem that seems to be outside the realms of my code.
Basically, I'm just doing a simple drag and drop handler for the
DataFormats.FileDrop type. Very simply, I just grab the string array
containing the paths to the files I want.
This is all very very easy, but recently I noticed this little anomaly: If
you drag and drop from Windows Explorer, using the List or Detail view, the
results you get from the IDataObject are not in the correct order! If you
switch your Explorer view to any view other than List or Detail, the files
are in the correct order.
Furthermore, the order they show up in List or Detail seems to be different
each subsequent drop.
Of course, the order of the files is very important to me.
I am running Windows XP Professional, SP2. .NET Framework 1.1 (no SP1).
You can try to replicate this problem by creating a new C# Windows
Application and add a single text box called txtOutput. Set txtOutput's
AllowDrop property to true, Multiline to true, and add the following event
txtOutput.DragDrop += new DragEventHandler(txtOutput_DragDrop);
txtOutput.DragEnter += new DragEventHandler(txtOutput_DragEnter);
Then drop the following two methods into your code:
private void txtOutput_DragEnter(object sender,
e.Effect = DragDropEffects.Copy;
private void txtOutput_DragDrop(object sender,
string droppedFiles = (string)e.Data.GetData(DataFormats.FileDrop);
foreach(string s in droppedFiles)
txtOutput.Text += String.Concat(System.IO.Path.GetFileName(s),"\r\n");
Compile and run your application. Now, open Windows Explorer to a folder of
your choice. Try dragging and dropping a specific selection of files in
various Explorer views. You should see the same symptoms I described above.
If you don't, then I apologize for taking your time :p.
Can anyone give me insight as to why this is happening, and how to work
around it (other than instruct my customers that they can't operate in List
or Detail view)?