views:

35

answers:

1

Hello,

I'm trying to get link to image file (src attribute) which I drag'n'drop from browser onto my desktop application. Image located inside an anchor (a-tag).

My code works with Chrome & Fx - but not with IE :(

if (e.Data.GetDataPresent("HTML Format"))
                {
                    string data = (string)e.Data.GetData(DataFormats.Html);

It seems like Explorer don't have any "HTML Format" Data sent to drg'n'drop mechanism, or I doing it wrong.

is there a way to get the image src from IE?

UPDATE I see, that if I select the link ("selection") with Image inside it, IE will send HTML Format. Fx and Chrome do the selection thing automatically upon dragging.

A: 

You have a couple of issues.

First, you should download the ClipSpy tool which will show you exactly what Formats are getting drag/dropped or copy/pasted. You will find that image SRC urls are stored in the UniformResourceLocatorW format, and there are various other formats available as well, including CF_HDROP which points to a local copy of the image file.

Secondly, you will find that the Drag/Drop doesn't work properly from Protected Mode IE on Vista and Windows 7 due to security restrictions. To enable drag/drop to your application, you must list your application in the registry.

You can register your application to accept web content from a drag-and-drop operation by creating a DragDrop policy. DragDrop policies must have a globally unique identifier (GUID) associated with them. Use CreateGuid to create a new GUID for your policy. Next, add a key to the following location.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Low Rights\DragDrop

Set the name of the new key to the GUID created for your policy and then add the following settings to the key.

  1. Policy (DWORD) should be set to 3, which tells Protected Mode to allow web content to be silently copied to your application process.
  2. AppName (REG_SZ) is the filename of your application executable file.
  3. AppPath (REG_SZ) is the user-selected install location of your application's executable file.
EricLaw -MSFT-
Thank you for your suggestion. I'm trying this under WinXp. ClipSpy App (great one) don't report neither CF_HDROP nor UniformResourceLocatorW. As I explained before: the html I'm dragging is like: <a href="#1"><img src="#2" /></a>
David