Windows Develop Bookmark and Share   
 index > Windows Forms General > [C#] DragDrop to Desktop/Explorer
 

[C#] DragDrop to Desktop/Explorer

i know how to handle file(s) are drap and drop into my window form.
but how to handle/achieve drad and drop into desktop/explorer?


thank you very much
codetale  Monday, August 27, 2007 2:31 PM
This worked for me:

public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.MouseDown += Form1_MouseDown;
}
private void Form1_MouseDown(object sender, MouseEventArgs e) {
string[] files = new string[] { @"c:\temp\test.txt" };
this.DoDragDrop(new DataObject(DataFormats.FileDrop, files), DragDropEffects.Copy);
}
}
nobugz  Monday, August 27, 2007 4:28 PM
This worked for me:

public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.MouseDown += Form1_MouseDown;
}
private void Form1_MouseDown(object sender, MouseEventArgs e) {
string[] files = new string[] { @"c:\temp\test.txt" };
this.DoDragDrop(new DataObject(DataFormats.FileDrop, files), DragDropEffects.Copy);
}
}
nobugz  Monday, August 27, 2007 4:28 PM
this work for me too
thankyou very much


another question,

this work for local drive files,
but what if network path? like FTP
my idea is download the selected items to temporary path after user drop on desktop/explorer, copy to drop path when finish download
but i totally no idea how to handle the event

thanks again
codetale  Monday, August 27, 2007 5:06 PM
Windows Explorer doesn't support this. You would have to write a drag and drop shell extension. You can't do that in .NET.
nobugz  Monday, August 27, 2007 5:36 PM
i see,
do you have any nice article/example about shell extension programming?

thankyou
codetale  Monday, August 27, 2007 5:50 PM
Google is usually good for that. Try this page.
nobugz  Monday, August 27, 2007 5:55 PM
thankyou so much
codetale  Monday, August 27, 2007 6:15 PM
I have read all parts about the article that you show me,
but there none of them are talking feedback(maybe i have missed something)


is there any way to know "where" user drop?

what i want to implement is:

when user drag the picture from my application and
drop it into desktop/explorer, then my application create a image file on the drop path

if user drop into others application like photoshop, then my application create a temporary file and send to photoshop

so, what i need to detect where user are dropping the item.

DoDragDrop seem only return DragDropEffects, so that only possible to check whether the task are complete/fail/cancel
codetale  Wednesday, August 29, 2007 8:47 AM
The DragDrop event must be implemented by the application that owns the window that you dropped on. There is no notification back to your app, other than the return value of DoDragDrop(). You cannot participate in the operation. So if you want to drop an FTP shortcut onto an Explorer window, you'll have to make Explorer smart enough to handle the required FTP transfer. Making it smart enough requires a shell extension handler. Perhaps D+D is not the best solution here.
nobugz  Wednesday, August 29, 2007 9:01 AM
thankyou for reply

i just found this article, it seem possible to did what i need without shell extension
How to drag a virtual file from your app into Windows Explorer

but i not sure it can implement in C# or not, because i don't know enough about interop
codetale  Wednesday, August 29, 2007 9:39 AM
The .NET framework doesn't support delayed rendering. I suppose it is possible, you have the native COM IDataObject interface definition available in System.Runtime.InteropServices.ComTypes. That grass is too tall for my mower though. Keep Googling, I'd assume somebody tried to implement it.
nobugz  Wednesday, August 29, 2007 10:10 AM
few months google'ing, but still no luck to get any managed delayed render

but i come out a stupid solution but it work(at least it work now, but dunno whether have side effest or not)

the solution is:
before DoDargDrop, i create a temparary file with unique name in temp folder,
then setup a FileSystemWatcher to watch all drive for creation of file,
and check whether is the unique name which i created, if that so, i get the file folder.
thats it, i got the drop target path

but now my problem is:
i dunno how exactly windows handle the notification,
so if the FileSystem contain many files, folders and subfolders,
will it cause problem? likeTongue Tiedystem crash, or slowdown system, etc...
codetale  Monday, November 05, 2007 4:51 AM

You can use google to search for other answers

Custom Search

More Threads

• Terminal Services: Run Program at Logon. How to execute logoff command right away after program closed
• I want to convert my source code in .exe file and...
• Access to VB.NET 2005 treeview growing pains
• Read-only multi-line texbox refresh problem
• statistical libraries in vb.net
• how to make toolstripmenu item go away immediately afer being selected
• Validation on VS2003 Datagrid
• :: I have never succeeded in hiding a property ::
• Showing a popup form using Application.run. Losing focus from main application.
• Transfer the value from form1 to form2