drag and drop file into textbox

Elevated privileges should not have anything to do with it. You also need to implement the DragOver event in addition to the DragDrop that Max answered. This is the code that should be added for DragDrop:

private void textBoxFile_DragOver(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; }


Check the AllowDrop property of your textbox - it should be set to true. Also, convert drag-drop data to string[] in case of DataFormats.FileDrop, not just string:

string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if(files != null && files.Length != 0)
{
    serverURLField.Text = files[0];
}

And I think you should swap code in your drag event handlers - usually you show user that drag-drop is possible in DragEnter and perform actual operation on DragDrop.

Tags:

C#