在Windows资源管理器中获取拖放文件的文件路径 [英] Get file path for drag-n-drop file on Windows Explorer

查看:162
本文介绍了在Windows资源管理器中获取拖放文件的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拖放是很多网站上一个很讨论的主题(这也是),我也发现了很好的问题,但没有回答这种情况。

drag-n-drop is a pretty discussed topic in a lot sites (this too) and i found nice questions too, but no answer to this case.

我有一些 listView 与某些元素,我需要它们在 Windows资源管理器上可以删除。删除后,我只需要删除文件路径,我不需要复制任何东西,只需要路径。

I have a listView with some elements and i need them to be droppable on the Windows Explorer. When dropped i need only the file path where those are dropped, i don't need to copy anything, just need the path.

类似的问题(为什么他们不为我工作):

Similar question (and why they don't work for me):


  • 拖放到桌面/资源管理器(这只有当您已经有要复制的文件并且没有给出路径时才有效)

  • < a href =http://blogs.msdn.com/b/delay/archive/2009/11/16/creating-something-from-nothing-and-knowing-it-developer-friendly-virtual-file-implementation- for-net-refine.aspxrel =nofollow noreferrer> http://blogs.msdn.com/b/delay/archive/2009/11/16/creating-something-from-nothing-and-knowing-it -developer-friendly-virtual-file-implementation-for-net-refine.aspx (这看起来不错,但它仍然创建一个虚拟文件并将其复制到该位置,因此我没有路径,仍然必须复制我的目的地的东西)

  • Drag and drop to Desktop / Explorer (this works only if you already have the file to copy and doesn't give path)
  • http://blogs.msdn.com/b/delay/archive/2009/11/16/creating-something-from-nothing-and-knowing-it-developer-friendly-virtual-file-implementation-for-net-refined.aspx (this looks good but it still create a virtual file and copy it to the location, so i have no path and still have to copy something in my destination)

我发现:

http://www.codeproject.com/Articles/23207/Drag-and-Drop-to-Windows-Folder-C

这样做非常非常,它创建一个文件监视器,创建一个虚拟文件,让DragDrop功能复制它,观察创建的位置,最后删除它。在我的Windows8.1中测试会导致浏览器不正确的刷新,我仍然可以看到文件,直到我刷新我的屏幕(F5)。

This works but in a very "unpratical" way, it creates a file watcher, create a dummy file, let the DragDrop function copy it, watch where it was created and finally delete it. Testing it in my Windows8.1 results in a incorrect Explorer refresh and i can still see the file until i refresh my screen (F5).

这是唯一的方法吗?我仍然不能相信我无法以更简单的方式实现这一点。

Is this the only way? I still can't believe i can't achieve this in a simpler way

推荐答案

想一下...如果你知道拖放,那么你会知道拖动源对将数据打包成正确的格式感到担忧,而拖动目标则担心以正确的格式检索数据。您的问题是您的拖动目标不在您的WPF应用程序中,因此数据丢失很少,您可以执行此操作。

Think about it for a minute... if you know about drag and drop, then you'll know that the drag source worries about packaging up the data into the correct format and the drag target worries about retrieving the data in the correct format. Your problem is that your drag target is not in your WPF application and so there is very little that you can do as the data is dropped.

一个更好的解决方案将是实现您自己的基本文件浏览器,然后作为应用程序的一部分,通过拖放操作访问文件路径将变得更加简单。无论如何,你有很多工作要做。

A much better solution would be to implement your own basic file browser and then as part of your application, it would be far simpler to access the file path with the drag and drop operation. Either way, you've got a lot of work to do.

这篇关于在Windows资源管理器中获取拖放文件的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆