question

GaborHorvath-7560 avatar image
0 Votes"
GaborHorvath-7560 asked GaborHorvath-7560 commented

How can be pasted remotely a locally copied file in C#?

Hi Experts,

A file (from File Explorer) has been copied using <Ctrl><C>. The content of the file must be pasted into a RichTextBox, if the file is a picture (e.g. in JPG format) - similarly to Microsoft Word. It's already implemented and works without any problem - but only locally. If the copied file was locally, but should be pasted on a Remote Desktop Computer, it doesn't work. The question is: why?

Copy/paste works locally/remotely, respectively, without any problem: e.g. a simple text (not a file!) or a picture (opened in Paint) can be copied/pasted (has been checked by Free Clipboard Viewer 4.0).

Some additional information:

Locally copied file, clipboard viewed locally

Clipboard contains data "DataFormats.FileDrop". Clipboard.GetDataObject().GetFormats() gives the following string array:

[0] "Shell IDList Array"
[1] "DataObjectAttributes"
[2] "DataObjectAttributesRequiringElevation"
[3] "Shell Object Offsets"
[4] "Preferred DropEffect"
[5] "AsyncFlag"
[6] "FileDrop"
[7] "FileNameW"
[8] "FileName"
[9] "FileContents"
[10] "FileGroupDescriptorW"

The whole path can be gained using Clipboard.GetFileDropList()[0] (or with FileNameW), and the picture can be imported into my application.

Locally copied file, clipboard viewed remotely

The format of the data is unknown (cannot be found in DataFormats class). Clipboard.GetDataObject().GetFormats() gives the following string array:

[0] "FileGroupDescriptorW"
[1] "FileContents"
[2] "Preferred DropEffect"
[3] "CanIncludeInClipboardHistory"
[4] "CanUploadToCloudClipboard"

Using "FileGroupDescriptorW" the name of the file (without the path) can be gained. Only the filename, without any path information (most probably the locally valid path information wouldn't be sense remotely).

Clipboard.GetData("FileContents") throws an exception: System.Runtime.InteropServices.COMException: 'Data on clipboard is invalid (Exception from HRESULT: 0x800401D3 (CLIPBRD_E_BAD_DATA))'

However the locally copied file:

  • can be pasted into the remote file system, or

  • can be pasted on remote PC e.g. into Microsoft Word without any problem. It means, that the content of the copied file can be found on the Clipboard - but not accessible. Most probably the "FileContents" should be suitable to get it.

Do you have any idea?

Many thanks in advance.

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

cheong00 avatar image
0 Votes"
cheong00 answered GaborHorvath-7560 commented

Instead of Clipboard.GetData(), try follow this example that uses Clipboard.GetDataObject().

The files be copied this way is in FileDrop dataformat that needs to be handled differently.

Also check this GitHub issue that suggest this could be a bug in .NET runtime for clipboard data handling.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you, most probably the GitHub issue could be the possible answer to the problem.

0 Votes 0 ·