将链接内的图像从 IE 拖放到 C#
我正在尝试获取图像文件(src 属性)的链接,我将其从浏览器拖放到桌面应用程序上。图像位于锚点(a-标签)内。
我的代码适用于 Chrome & Fx - 但不适用于 IE :(
if (e.Data.GetDataPresent("HTML Format"))
{
string data = (string)e.Data.GetData(DataFormats.Html);
看来资源管理器没有任何“HTML 格式”数据发送到 drg'n'drop 机制,或者我做错了。
有没有办法从 IE 获取图像 src?
<强>更新 我发现,如果我选择其中包含图像的链接(“选择”),IE 将发送 HTML 格式。 Fx 和 Chrome 在拖动时会自动执行选择操作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有几个问题。
首先,您应该下载 ClipSpy 工具,它将准确地向您显示格式是什么拖/放或复制/粘贴。您会发现图像 SRC url 以 UniformResourceLocatorW 格式存储,并且还有各种其他可用格式,包括指向图像文件的本地副本的 CF_HDROP。
其次,您会发现由于安全限制,在 Vista 和 Windows 7 上的保护模式 IE 中拖放功能无法正常工作。要启用对应用程序的拖放功能,您必须在注册表中列出您的应用程序。
您可以通过创建 DragDrop 策略来注册您的应用程序以接受来自拖放操作的 Web 内容。 DragDrop 策略必须具有与其关联的全局唯一标识符 (GUID)。使用 CreateGuid 为您的策略创建新的 GUID。接下来,将密钥添加到以下位置。
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Low Rights\DragDrop
将新项的名称设置为为策略创建的 GUID,然后将以下设置添加到该项。
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.