The title says it all.
What I would like to be able to do is drag a folder from Windows explorer on
to a form and just capture the full path and folder name.
Failing the fully qualified path, I absolutely need the folder name (which I
could find by iterating throught the folder structure)

All the doc I can find refers to dropping the data associated with an
object - and the Help topic
"Performing Drag-and-Drop Operations in Windows Forms"
Has not done much for me.
Am I missing something here?
Is what I want to do even possible?

RE: Drag & Drop Folder Name from Windows Explorer to a Windows Form by v-jetan

v-jetan
Tue Aug 16 23:26:04 CDT 2005

Hi David,

Thanks for your post.

What you want is the windows shell drag&drop support. Currently, there is
no build-in support for doing shell drag&drop in Winform. However, we can
p/invoke some Shell API to get this done.

Below is a little sample I wrote to demonstrate what you want(we can place
this code snippet in any form class):

private const int WS_EX_ACCEPTFILES=0x00000010;
protected override CreateParams CreateParams
{
get
{
CreateParams cp=base.CreateParams;
cp.ExStyle=cp.ExStyle|WS_EX_ACCEPTFILES;
return cp;
}
}

[DllImport("shell32.dll", CharSet=CharSet.Auto)]
public static extern int DragQueryFile(IntPtr hDrop, int iFile,
StringBuilder lpszFile, int cch);

[DllImport("shell32.dll")]
static extern void DragFinish(IntPtr hDrop);

private const int WM_DROPFILES=0x0233;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_DROPFILES)
{
int iNumChars=DragQueryFile(m.WParam , 0, null, 0);
StringBuilder szDropFilePath = new StringBuilder(iNumChars+1);

DragQueryFile(m.WParam , 0, szDropFilePath, iNumChars+1);

DragFinish(m.WParam );
this.Text=szDropFilePath.ToString();
}
base.WndProc (ref m);
}

First, we add WS_EX_ACCEPTFILES window extended style to our form, this
will enable our form to accept shell file drop and display an accept icon
for dragging.

Whenever a file is dragged over our form, WM_DROPFILES will be posted to
the form WndProc. In this notificaiton, we can P/invoke DragQueryFile Shell
API to get the dropped files collection. Currently, I just pass 0 for the
second parameter to get the first file in the dropped file collection. For
more detailed usage of this API, please search it in MSDN documentation.

Hope this helps.
===================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Re: Drag & Drop Folder Name from Windows Explorer to a Windows Form by Lloyd

Lloyd
Tue Aug 16 23:54:17 CDT 2005

This is a multi-part message in MIME format.

------=_NextPart_000_0090_01C5A33B.8A8A6210
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

test that, that should gives you some idea....

public partial class Form1 : Form
{
public Form1()
{
AllowDrop =3D true;
}
protected override void OnDragEnter(DragEventArgs drgevent)
{
base.OnDragEnter(drgevent);
string[] fmt =3D drgevent.Data.GetFormats();
foreach (string s in fmt)
Console.WriteLine(s);
Console.WriteLine(drgevent.Data.GetData(DataFormats.FileDrop));
}
}

And remember, use the force, Oops, I mean the debugger is your friend!

------=_NextPart_000_0090_01C5A33B.8A8A6210
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2722" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>
<DIV>test that, that should gives you some idea....</DIV>
<DIV><BR><FONT color=3D#0000ff size=3D2>public</FONT><FONT size=3D2> =
</FONT><FONT=20
color=3D#0000ff size=3D2>partial</FONT><FONT size=3D2> </FONT><FONT =
color=3D#0000ff=20
size=3D2>class</FONT><FONT size=3D2> </FONT><FONT color=3D#008080=20
size=3D2>Form1</FONT><FONT size=3D2> : </FONT><FONT color=3D#008080=20
size=3D2>Form<BR></FONT><FONT size=3D2>{<BR></FONT><FONT color=3D#0000ff =

size=3D2>&nbsp;&nbsp;&nbsp; public</FONT><FONT size=3D2>=20
Form1()<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

AllowDrop =3D </FONT><FONT color=3D#0000ff size=3D2>true</FONT><FONT=20
size=3D2>;<BR>&nbsp;&nbsp;&nbsp; }<BR></FONT><FONT color=3D#0000ff=20
size=3D2>&nbsp;&nbsp;&nbsp; protected</FONT><FONT size=3D2> </FONT><FONT =

color=3D#0000ff size=3D2>override</FONT><FONT size=3D2> </FONT><FONT =
color=3D#0000ff=20
size=3D2>void</FONT><FONT size=3D2> OnDragEnter(</FONT><FONT =
color=3D#008080=20
size=3D2>DragEventArgs</FONT><FONT size=3D2> =
drgevent)<BR>&nbsp;&nbsp;&nbsp;=20
{<BR></FONT><FONT color=3D#0000ff size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
base</FONT><FONT size=3D2>.OnDragEnter(drgevent);<BR></FONT><FONT =
color=3D#0000ff=20
size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; string</FONT><FONT =
size=3D2>[] fmt =3D=20
drgevent.Data.GetFormats();<BR></FONT><FONT color=3D#0000ff=20
size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; foreach</FONT><FONT =
size=3D2>=20
(</FONT><FONT color=3D#0000ff size=3D2>string</FONT><FONT size=3D2> s =
</FONT><FONT=20
color=3D#0000ff size=3D2>in</FONT><FONT size=3D2> fmt)<BR></FONT><FONT =
color=3D#008080=20
size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
Console</FONT><FONT size=3D2>.WriteLine(s);<BR></FONT><FONT =
color=3D#008080=20
size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Console</FONT><FONT=20
size=3D2>.WriteLine(drgevent.Data.GetData(</FONT><FONT color=3D#008080=20
size=3D2>DataFormats</FONT><FONT =
size=3D2>.FileDrop));<BR>&nbsp;&nbsp;&nbsp;=20
}<BR>}</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>And remember, use the force, Oops, I mean the =
debugger is your=20
friend!</DIV></FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0090_01C5A33B.8A8A6210--


Re: Drag & Drop Folder Name from Windows Explorer to a Windows Form by David

David
Wed Aug 17 11:10:02 CDT 2005

Thanks Jefferey and Lloyd for the quick responses to myt first post in this
forum.
I will check ithis and post back presently.



Re: Drag & Drop Folder Name from Windows Explorer to a Windows Form by v-jetan

v-jetan
Wed Aug 17 20:37:42 CDT 2005

Hi David,

You are welcome. Please feel free to feedback any progress here, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Re: Drag & Drop Folder Name from Windows Explorer to a Windows Form by v-jetan

v-jetan
Mon Aug 22 03:36:36 CDT 2005

Hi David,

Have tried my code snippet? Is your problem resolved? Please feel free to
tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.