Question Drag drop from FTP-location in Windows Explorer

timdelma

Member
Joined
May 3, 2012
Messages
8
Programming Experience
10+
We're looking for a way to drag a file from a FTP-location in Windows Explorer to .NET...
So I have a FTP-location open in Windows Explorer and I want to drag a (any) file or directory to a .NET-control.

Does anyone know how to get this done ?
 
"UniformResourceLocator" data format will provide you the url.
 
Ok, in the DragEnter i check for the "UniformResourceLocator" data format. That part works perfect.

But how do I retrieve the FTP-URL in the DragDrop-event? Because the "
UniformResourceLocator"-dataformat only returns True/False...
The Data.GetDataPresent(DataFormats.Text) only returns url's when you drop an url from Internet Explorer. But I dragging from an FTP-location in Windows Explorer...

 
Ignore my previous post. I managed to get the url out of the drop-data, but now I have another annoying problem :apologetic: :

When the user logged in to the FTP-location in Windows Explorer he/she had to enter the username and password. When I retrieve the URL out of the drop-data, this URL only contains the username and not the password. When I use another function to download the file from this URL (FTP-connection is still open in Windows Explorer !), I get the 'Authentication failed'-exception because the password is missing. When I manually alter the URL and add the password the download works splendid...

Any idea how to retrieve the password from the drop-data ??? Or is there another way ? The user has already entered his password so I can't ask him to do this again...
 
The user has already entered his password so I can't ask him to do this again...

Um, yes you can. Your application has to make a new connection to the FTP server so it needs to provide the credentials. If you were able to get the password from Windows Explorer then that would represent a security hole. If the user wants to use two separate applications to perform this task then they will have to accept that they need to provide both applications with their password.
 
You have a point. But it's an extra action required from the user :suspicion:
Thing is: when you drag a file from the FTP-location to another Windows Explorer-window no password is asked and that window is another instance of Windows Explorer. So why does this work ?
 
Another thing: when you drop 2 or more files at the same time in .NET the "UniformResourceLocator"-dataformat isn't recognized. Any idea how the handle multiple files ?
 
You have a point. But it's an extra action required from the user :suspicion:
Thing is: when you drag a file from the FTP-location to another Windows Explorer-window no password is asked and that window is another instance of Windows Explorer. So why does this work ?

It's another Windows Explorer window but it's still Windows Explorer so it already has the password. If you created two forms in your own app and the user provided a password in one would you be able to use it in the other? Of course you would, because it's just two forms within the same application. Same goes for Windows Explorer.
 
Another thing: when you drop 2 or more files at the same time in .NET the "UniformResourceLocator"-dataformat isn't recognized. Any idea how the handle multiple files ?

Drag & Drop in Windows Forms

Post #3 should be of particular interest to you. Haven't actually tried it in this particular scenario but it should be just as useful here as anywhere else.
 
You have a point. But it's an extra action required from the user :suspicion:
Thing is: when you drag a file from the FTP-location to another Windows Explorer-window no password is asked and that window is another instance of Windows Explorer. So why does this work ?
Another thing: when you drop 2 or more files at the same time in .NET the "UniformResourceLocator"-dataformat isn't recognized. Any idea how the handle multiple files ?
The standard .Net implementation of drag and drop does not support it, you have to use the COM objects to achieve both these requests. Here's an article with C# samples that explains it well: Outlook Drag and Drop in C# - CodeProject®
 
Back
Top