We are attempting to allow our users to use Drag n Drop onto a control in a
WinForms v2 application.

Within the control_DragDrop() event handler we want to determine the name
and location for a file that was dropped onto this control. We are
moderately familiar with performing DnD from within our application - we do
this between various controls within the app itself - but, a lot to learn
when it comes to DnD and external files from outside our application.

We are successfully determining that the user is trying to drop a file onto
the control with the following code in the DragEnter() event handler:

if (e.Data.GetDataPresent( DataFormats.FileDrop ))
{
Console.WriteLine("A file was dropped .......");
}

What we're trying to do now, is create a File object (or something similar
that you might recommend) using the file the user has dropped so that we can
get to its contents, file name, date it was created, etc., etc. Just not
sure how to get the handle to the file??

Thanks
--
Stay Mobile

Re: Drag & Drop ... getting a handle to the file that was dropped. by Chris

Chris
Sun Oct 22 03:13:27 CDT 2006

Hi,

If I understand your question correctly, you can ue the GetData method, for
FileDrop it will return a string[] of the file paths.
string[] filePaths = e.Data.GetData(DataFormats.FileDrop)

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"MobileMan" <MobileMan@discussions.microsoft.com> wrote in message
news:459F2922-D58B-4191-A8D7-CD0668057FDE@microsoft.com...
> We are attempting to allow our users to use Drag n Drop onto a control in
> a
> WinForms v2 application.
>
> Within the control_DragDrop() event handler we want to determine the name
> and location for a file that was dropped onto this control. We are
> moderately familiar with performing DnD from within our application - we
> do
> this between various controls within the app itself - but, a lot to learn
> when it comes to DnD and external files from outside our application.
>
> We are successfully determining that the user is trying to drop a file
> onto
> the control with the following code in the DragEnter() event handler:
>
> if (e.Data.GetDataPresent( DataFormats.FileDrop ))
> {
> Console.WriteLine("A file was dropped .......");
> }
>
> What we're trying to do now, is create a File object (or something similar
> that you might recommend) using the file the user has dropped so that we
> can
> get to its contents, file name, date it was created, etc., etc. Just not
> sure how to get the handle to the file??
>
> Thanks
> --
> Stay Mobile



Re: Drag & Drop ... getting a handle to the file that was dropped. by MobileMan

MobileMan
Sun Oct 22 09:04:01 CDT 2006

Thanks Chris - that works perfect!!

I feel a bit silly for not having thought this through better ... I noticed
yesterday when I was messing around and experimenting with this code that the
toString() method resulted in a string array ... didn't even dawn on me that
these might be the file paths.

We use "Windows Forms 2.0 Programming" by Sells as a bible on our desktops.
He has a good section on DnD ... even discusses "document management" in the
sense of being able to DnD your own file types back onto the form to open the
document. But in his code there's a limitation that we can only do this on
the "main" form (our design is a MDI style app) because he's using interop to
register and listen for the WM_DROPFILES message. By calling the
DragQueryFile function (both to determine how many files where dropped, then
again [different params the second call] to get the paths) we can do the same
thing - but with the limitation that this can only run on the main form.
Works great but we need this on the MDI child form, which - thank you - your
suggestion supports.

The "devil is in the details," as someone once said. Again, thanks Chris
... really appreicate the help.

--
Stay Mobile


"Chris Taylor" wrote:

> Hi,
>
> If I understand your question correctly, you can ue the GetData method, for
> FileDrop it will return a string[] of the file paths.
> string[] filePaths = e.Data.GetData(DataFormats.FileDrop)
>
> Hope this helps
>
> --
> Chris Taylor
> http://dotnetjunkies.com/weblog/chris.taylor
> "MobileMan" <MobileMan@discussions.microsoft.com> wrote in message
> news:459F2922-D58B-4191-A8D7-CD0668057FDE@microsoft.com...
> > We are attempting to allow our users to use Drag n Drop onto a control in
> > a
> > WinForms v2 application.
> >
> > Within the control_DragDrop() event handler we want to determine the name
> > and location for a file that was dropped onto this control. We are
> > moderately familiar with performing DnD from within our application - we
> > do
> > this between various controls within the app itself - but, a lot to learn
> > when it comes to DnD and external files from outside our application.
> >
> > We are successfully determining that the user is trying to drop a file
> > onto
> > the control with the following code in the DragEnter() event handler:
> >
> > if (e.Data.GetDataPresent( DataFormats.FileDrop ))
> > {
> > Console.WriteLine("A file was dropped .......");
> > }
> >
> > What we're trying to do now, is create a File object (or something similar
> > that you might recommend) using the file the user has dropped so that we
> > can
> > get to its contents, file name, date it was created, etc., etc. Just not
> > sure how to get the handle to the file??
> >
> > Thanks
> > --
> > Stay Mobile
>
>
>