0

In my c# Win Form app I am using Drag and Drop feature. A user should drag and drop a folder and my app checks if the folder exist. One user tried drag and drop a link/shotcut and got the error message. It gives me an idea to check on the object dropped if it is a folder, file or link.

Here is my code:

void Form1_DragDrop(object sender, DragEventArgs e)
{
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
    TB_folder.Text = files[0].Trim();

    if  (Directory.Exists(TB_folder.Text) != true)
        .................

Is there a way to check if the "DragEventArgs e" is a file, link or folder?

Thanks,

zb

doctorlove
  • 18,872
  • 2
  • 46
  • 62
Zalek Bloom
  • 551
  • 6
  • 13
  • Your question is unclear. What error message did the user get? Is the code you posted the code that gives the error? It looks like you already have code to ensure that it's a folder (the `Directory.Exists` call). Are you saying that `Directory.Exists` returns `true` for links and shortcuts? – Jim Mischel Jun 14 '16 at 16:47
  • If object dragged is not a folder, the program display message "invalid folder". What I want is display error message, if the dragged object is a file. If the dragged object is a link/shortcut of the folder and the folder does not exist - the program displays error message. I am checking if a program is a link - it the last 4 characters are ".lnk" - I don't like this solution - I would prefer check some property/type to verify if it is a link. – Zalek Bloom Jun 14 '16 at 19:08
  • The information at http://stackoverflow.com/questions/1485155/check-if-a-file-is-real-or-a-symbolic-link should help you out. – Jim Mischel Jun 14 '16 at 19:19

0 Answers0