Save any file type copied into the Clipboard

1.2k Views Asked by At

I'm working with the code from this Stack article (specifically the second answer) to monitor when the clipboard changes. 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. I would set file size limits though so that the temp folder doesn't get overloaded. 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 (i.e. usage: DataFormats.Bitmap), I can't find a catch-all for any file type, or for folders. 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. It seems I can't get bytes from a DataObject type, which would be the easy way out.

Any ideas on how I could accomplish this? Thanks.

1

There are 1 best solutions below

3
On

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();

But couldn't you just serialize (to exact copy) what ever data comes in and save it as the last entry in Clipboard.GetFileDropList();

seems like all files that arent audio/images/string has a very specific set of formats well anyway, just my thoughts

maybe look here http://www.codeproject.com/Articles/15333/Clipboard-backup-in-C