Click here to Skip to main content
15,897,122 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi I am trying to drag and drop a file on to a wpf window. I can get to here but I no data is available? I would like to get the file path such as
C:\\folder\\data.raw

C#
private void Window_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("FileName"))
            {

                string folderPath = Convert.ToString(e.Data.GetData("FileName"));
                object data = e.Data.GetData(typeof(Object));
                //do whatever you need to do with the folder path
            }
        }

AllowDrop="True" Drop="Window_Drop"
Posted

1 solution

Hi, This is basically what you want to do.

C#
private void ImagePanel_Drop(object sender, DragEventArgs e)
{

  if (e.Data.GetDataPresent(DataFormats.FileDrop))
  {
    // Note that you can have more than one file.
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

    // Assuming you have one file that you care about, pass it off to whatever
    // handling code you have defined.
    HandleFileOpen(files[0]);
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900