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

0

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 on a Remote Desktop Computer, it doesn't work. The question is: why?

Copy/paste works remotely 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:

  1. Locally copied file

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.

  1. Remotely copied file

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 out. 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 remotely copied file:

  1. can be pasted into the local file system, or
  2. can be pasted 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.

c#
exception
clipboard
remote-desktop
asked on Stack Overflow Apr 15, 2021 by HvG • edited Apr 15, 2021 by HvG

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0