简体   繁体   English

保存复制到剪贴板的任何文件类型

[英]Save any file type copied into the Clipboard

I'm working with the code from this Stack article (specifically the second answer) to monitor when the clipboard changes. 我正在使用此Stack文章中的代码(特别是第二个答案)来监视剪贴板何时更改。 The end goal for this application is that the user can copy any file type (whether it's a .xlsx, .pk3, .sln, etc), folder, an image or a string and have it automatically saved to their temp directory. 该应用程序的最终目标是用户可以复制任何文件类型(无论是.xlsx,.pk3,.sln等),文件夹,图像还是字符串,并将其自动保存到其临时目录中。 I would set file size limits though so that the temp folder doesn't get overloaded. 不过,我将设置文件大小限制,以使temp文件夹不会过载。 The overall concept of the application is to provide convenience, so users can recover data that was copied but then deleted or lost. 该应用程序的总体概念是提供便利,因此用户可以恢复已复制但随后删除或丢失的数据。

So far, the above referenced code is working great for strings and images. 到目前为止,以上引用的代码对于字符串和图像非常有效。 However, after reviewing the items in the DataFormats list (ie usage: DataFormats.Bitmap), I can't find a catch-all for any file type, or for folders. 但是,在查看了DataFormats列表中的项目(即用法:DataFormats.Bitmap)之后,我找不到任何文件类型或文件夹的包罗万象。 I also can't find any way to determine what type of file was copied. 我也找不到确定复制文件类型的任何方法。 Is there any way to determine that? 有什么办法可以确定吗? For example, if there was a way to get the file extension of the file copied, that would help. 例如,如果有一种方法可以复制文件的文件扩展名,那么会有所帮助。

Maybe my hopes are set too high. 也许我的希望太高了。 Even if I kept an array of allowed file types (.xlsx, .sln, etc) there would be no way I can think of to save that type of file. 即使我保留了允许的文件类型(.xlsx,.sln等)数组,也无法想到保存该类型的文件。 It seems I can't get bytes from a DataObject type, which would be the easy way out. 看来我无法从DataObject类型获取字节,这将是简单的方法。

Any ideas on how I could accomplish this? 关于如何实现此目标的任何想法? Thanks. 谢谢。

The reason, why you can't find a catch all, is because every format is registered on the host machine, by the applications using that file format. 之所以找不到全部内容,是因为每种格式都是由使用该文件格式的应用程序在主机上注册的。 you can get the current list of fileformats that the object held in the clipboard has by using string[] formats = iData.GetFormats(); 您可以使用string [] format = iData.GetFormats();获取剪贴板中保存的对象具有的文件格式的当前列表。

But couldn't you just serialize (to exact copy) what ever data comes in and save it as the last entry in Clipboard.GetFileDropList(); 但是您不能只是序列化(精确复制)所有数据,然后将其保存为Clipboard.GetFileDropList()的最后一个条目。

seems like all files that arent audio/images/string has a very specific set of formats well anyway, just my thoughts 似乎所有arent音频/图像/字符串文件都有一组非常特定的格式,只是我的想法

maybe look here http://www.codeproject.com/Articles/15333/Clipboard-backup-in-C 也许看这里http://www.codeproject.com/Articles/15333/Clipboard-backup-in-C

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM