HI,
How to drag and drop folders/files from One Wi开发者_如何学JAVAndows Explorer to another windows explorer in C# ? Internally when i drag and drop from one explorer to another upload should happen I am using FTP
My requirement is like i have to drag and drop files,folders... to FTP folder in windows explorer ?Any code snippet...
If the file already exists you can do it like this: DoDragDrop
If the file does not exists then this how to do it: Transferring Virtual Files to Windows Explorer in C#
When you want to be the Drop Target, you need to enable dropping on the form:
AllowDrop = true;
At that point, you need to wire up some of the event handlers:
- ItemDrag
- DragOver
- DragEnter
- DragLeave
- DragDrop
So if you had a listbox and wanted to list the files dropped, something like:
private void listBox1_DragDrop(object sender, DragEventArgs e)
{
foreach (string fileName in (string[])e.Data.GetData(DataFormats.FileDrop) )
{
listBox1.Items.Add( fileName );
}
}
To be the Drop Source, slightly more work and works best if you actually have a file-name to a real file (see the MSDN link), there is a complete series that describes all of the tricks Shell Style Drag and Drop in .NET which provides a complete library for you to use.
Some sources:
- Drag and Drop Using C#
- Drag and Drop using C# - another one with the same title.
- How to provide file drag-and-drop functionality in a Visual C# application
- MSDN Performing Drag-and-Drop Operations in Windows Forms
This code snippet is pretty close to drag from "item" (just replace the "test.txt" string) to any explorer window (including ftp), when user is moving the item manually.
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);
}
精彩评论