0

I am trying to get a url of a dragged item on winforms. It's not capturing.

The following code works for local applications dragging from local drive it captures location. But dragging from browser its preventing.

Debug Image Click Here to See

Example I have a browser url http://example.com/image.jpg

When I tried to drag and drop unable to capture the link location of the file.

string[] files = (string[])e.Data.GetData(DataFormats.FileDrop,false);
        if(files != null && files.Length!=0)
        {
            wp_fetch_url.Text = files[0];
        }
dev
  • 1
  • 4
  • 1
    Set a breakpoint and examine the DataFormat that you are getting. Is the drop event getting raised? It could be that you are receiving a url in text format. – Emond Jan 27 '17 at 09:37
  • Perhaps the browser doesn't pass it as a file, so `FileDrop` is most likely not applicable here. – Joey Jan 27 '17 at 09:54
  • @ErnodeWeerd Can you please look at updated question. I have attached debug image. How do I know what type of data source it is and how to work with it. – dev Jan 27 '17 at 10:58
  • @Joey Can you please look at updated question. I have attached debug image. How do I know what type of data source it is and how to work with it. – dev Jan 27 '17 at 10:58
  • You have to drill down further. Open Values and open the first Item in Values – Emond Jan 27 '17 at 11:12

1 Answers1

0

Try this:

string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
{
  if (Path.GetExtension(file[0]) == ".url")
  {
   wp_fetch_url.Text = file[0];
  }
 }
Svekke
  • 1,470
  • 1
  • 12
  • 20