** ADDENDUM: After some serious hours of research i found that i was barking up the wrong tree. The problem was not the clipboard itself but what happens if you feed it malformed unicode text which i apparently did. My editor had no problem handling it but when the clipboard got it it was truncated at the point where the error was in the text. Reading 'damaged' file content will have the same effect when strings are handled in the application later and i therefore now use the Encoder/DecoderExceptionFallback() functionality to detect errors. Quite an eye opener. **
I have a problem with the Clipboard in my winforms C# application. I'm trying to save a very long text to the clipboard (>1.4 million chars) and when using the DataFormats.UnicodeText i cannot get back the same amount of text. In a specific case i copy 1469785 characters but get back only 502228 chars. If i tag the data as DataFormats.WaveAudio and then force as string cast at the call to Clipboard.GetData() i actually get the correct number of characters back. There seems to be some special handling when using text only.
This doesn't work:
Clipboard.SetData( System.Windows.Forms.DataFormats.UnicodeText, _sb.ToString() );
StringBuilder _sb2 = new StringBuilder( Clipboard.GetData( DataFormats.UnicodeText ) );
While this does:
Clipboard.SetData( System.Windows.Forms.DataFormats.WaveAudio, _sb.ToString() );
StringBuilder _sb2 = new StringBuilder( ( string )Clipboard.GetData( DataFormats.WaveAudio ) );
Using DataFormat.Text didn't help either but added the mangling of the unicode characters (for obvious reasons :D).
All information i can find on the net says there is no limitation on clipboard size short of the available memory so how can this be explained? Is there really some special handling with the text data format? I'm sure i'm missing some cruical thing here but what?
There is no limit, at least when using the windows API. However, unless you intend for some other app to be able to paste this, there's probably no point in using the clipboard in the first place.