Reputation: 3310
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.
Upvotes: 1
Views: 2150
Reputation: 57115
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.
Upvotes: 3