I’m trying to copy a custom object from a RDC window into host (my local) machine. It fails. Here’s the code that i’m using to 1) copy and 2) paste:
1) Remote (client running on Windows XP accessed via RDC):
//copy entry IDataObject ido = new DataObject(); XmlSerializer x = new XmlSerializer(typeof(EntryForClipboard)); StringWriter sw = new StringWriter(); x.Serialize(sw, new EntryForClipboard(entry)); ido.SetData(typeof(EntryForClipboard).FullName, sw.ToString()); Clipboard.SetDataObject(ido, true);
2) Local (client running on local Windows XP x64 workstation):
//paste entry IDataObject ido = Clipboard.GetDataObject(); DataFormats.Format cdf = DataFormats.GetFormat(typeof(EntryForClipboard).FullName); if (ido.GetDataPresent(cdf.Name)) //<- this always returns false { //can never get here! XmlSerializer x = new XmlSerializer(typeof(EntryForClipboard)); string xml = (string)ido.GetData(cdf.Name); StringReader sr = new StringReader(xml); EntryForClipboard data = (EntryForClipboard)x.Deserialize(sr); }
It works perfectly on the same machine though.
Any hints?
Ok, found what the issue was. Custom format names get truncated to 16 characters when copying over RDC using custom format. In the line
the format name was quite long.
When i was receiving the copied data on the host machine the formats available had my custom format, but truncated to 16 characters.
So i just used a shorter format name: