Copy byte array to clipboard

I am trying to execute a client-server program in which I can split the contents of the clipboard.

Now I can share it if the content type is audio, image or text. The idea is that I convert the contents to an array of bytes, send it, convert it back to its original type ( Stream , BitmapSource or string ) and paste it into the client clipboard using the Clipboard.SetAudio , Clipboard.SetImage or Clipboard.SetText methods .

My problem is that there are several files in the clipboard. I use the Clipboard.GetFileDropList method to get a list of files, and for each file in the list I convert it to an array of bytes and send it to the client. How can I paste this byte array into the client clipboard?

I know that there is a Clipboard.SetFileDropList method, but it requires me to provide a list of files, and since the file does not exist on the client, I cannot use it.

How can I solve this problem?

+5
source share
1 answer

For the client to treat files as perishable, they must exist in the client file system in some way, because the clipboard expects a list of file names when setting up the contents of the clipboard.

This can be done by transferring the data in the form of a stream to your client, and then making the client immediately unpack this stream into a temporary folder, the path to which can be obtained via:

 var temp = Environment.ExpandEnvironmentVariables("%TEMP%"); 

Once you have done this and the files are in place, you can put these files on the clipboard as if they were copied.

We will warn you that support for copying / pasting files, instead of being able to β€œtransfer” files, could work much slower than other operations, due to how large the files can be.

+3
source

All Articles