0

I have a panel on my form on which I have allowed drag and drop. I have written the code to DragEnter and DragDrop events and they were working fine last time I checked. But now when I drag a file over my panel I get the forbidden cursor and the events are no longer triggered. I have looked in my entire project to see if I am disabling AllowDrop somewhere, but I don't.

Here are my events together with the functions they are performing:

this.pnlNoPostbagFolder.AllowDrop = true;

this.pnlNoPostbagFolder.DragDrop += new System.Windows.Forms.DragEventHandler(this.pnlNoPostbagFolder_DragDrop);
this.pnlNoPostbagFolder.DragEnter += new System.Windows.Forms.DragEventHandler(this.pnlNoPostbagFolder_DragEnter);

private void pnlNoPostbagFolder_DragDrop(object sender, DragEventArgs e)
{
    FileListDragDrop(sender, e);
}

private void pnlNoPostbagFolder_DragEnter(object sender, DragEventArgs e)
{
    FileListDragEnter(sender, e);
}

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

private void FileListDragDrop(object sender, DragEventArgs e)
{
    string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
    for (int i = 0; i < s.Length; i++)
    {
        if (Path.GetExtension(s[i]).Equals(".csv", StringComparison.InvariantCultureIgnoreCase) || Path.GetExtension(s[i]).Equals(".sql", StringComparison.InvariantCultureIgnoreCase))
        {
            string source = s[i];
            string destination = Common.Conf.PostbagFolderLocation + "\\" + Path.GetFileName(s[i]);
            if (File.Exists(destination))
            {
                DialogResult dr = MsgBox.Show(string.Format("A file named '{0}' already exists in the Postbag folder. Overwrite?", Path.GetFileName(s[i])), "File Exists", MsgBox.Buttons.YesNo, MsgBox.Icon.Question);
                if (dr == DialogResult.Yes)
                {
                    File.Copy(source, destination, true);
                    RefreshPostbagFolder();
                }

            }
            File.Copy(source, destination, true);
        }
        else
            MsgBox.Show("File extension not supported", "Add File", MsgBox.Buttons.OK, MsgBox.Icon.Error);
    }
}
disasterkid
  • 6,948
  • 25
  • 94
  • 179

1 Answers1

2

All of your code seems OK and I don't have any issue with your code in my machine, It seems a UAC issue:

Community
  • 1
  • 1
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398