Get the path of a file dragged into a Windows Forms form

matrix picture matrix · Dec 6, 2010 · Viewed 34.5k times · Source

I am developing an application which requires the user to drag a file from Windows Explorer into the application window (Windows Forms form). Is there a way to read the file name, path and other properties of the file in C#?

Answer

Adrian Fâciu picture Adrian Fâciu · Dec 6, 2010

You can catch the DragDrop event and get the files from there. Something like:

void Form_DragDrop(object sender, DragEventArgs e)
{
    string[] fileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);

    //more processing
}