0

I am currently using a file dialog to export a file, but I was wondering how I could export my file using drag and drop. I couldn't figure out how to get the file path of where the item is being dropped. Here is the code that I used for open file dialogue in case its required.

if (this.listView1.SelectedItems.Count > 0)
{
    ListViewItem item = this.listView1.SelectedItems[0];
    string text = this.faderLabel8.Text;
    if (!text.EndsWith(@"\"))
    {
        text = text + @"\";
    }

    using (SaveFileDialog dialog = new SaveFileDialog())
    {
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            Jtag.ReceiveFile(item.SubItems[0].Text, text + item.SubItems[0].Text);
        }
    }
}
CDspace
  • 2,639
  • 18
  • 30
  • 36
RunFTL
  • 5
  • 4

2 Answers2

0

If you want it to be useful through "drag and drop" you would require some sort of graphical interface that displays the files in a container where they are and then another container to where you want to move them. When you highlight an item with your mouse you add them to your itemList and when your drop them you copy them. Just make sure the List is emptied once in case you remove the highlight.

0

You don't need the path of where the file is being dropped. Instead you need to create a temporary file.

  1. Save file to a temporary folder
  2. Initiate drag on an event/command, such as mouse down, in the following way:
//(This example is uses WPF/System.Windows.DragDrop)
//Create temporary file
string fileName = "DragDropSample.txt";
var tempPath = System.IO.Path.GetTempPath();
var tempFilePath = System.IO.Path.Combine(tempPath, fileName);
System.IO.File.WriteAllText(tempFilePath, "Testing drag and drop");
//Create DataObject to drag
DataObject dragData = new DataObject();
dragData.SetData(DataFormats.FileDrop, new string[] { tempFilePath });
//Initiate drag/drop
DragDrop.DoDragDrop(dragSourceElement, dragData, DragDropEffects.Move);

For WinForms example and more details see: Implement file dragging to the desktop from a .net winforms application?