Create System.Windows.DataObject with given html and plain-text ready to be used for clipboard or drag and drop.
Handle missing ]]> tags, specified startend segments and Unicode characters.
public static DataObject CreateDataObject(string html, string plainText)
Parameters
html
a html fragment
plainText
the plain text
Remarks
Windows Clipboard works with UTF-8 Unicode encoding while .NET strings use with UTF-16 so for clipboard to correctly decode Unicode string added to it from .NET we needs to be re-encoded it using UTF-8 encoding. Builds the CF_HTML header correctly for all possible HTMLs<br /> If given html contains start/end fragments then it will use them in the header: <pre><![CDATA[<html><body><!--StartFragment-->hello <b>world</b><!--EndFragment--></body></html>]]></pre> If given html contains html/body tags then it will inject start/end fragments to exclude html/body tags: <pre><![CDATA[<html><body>hello <b>world</b></body></html>]]></pre> If given html doesn't contain html/body tags then it will inject the tags and start/end fragments properly: <pre><![CDATA[hello <b>world</b>]]></pre> In all cases creating a proper CF_HTML header:<br /><pre><![CDATA[ Version:1.0 StartHTML:000000177 EndHTML:000000329 StartFragment:000000277 EndFragment:000000295 StartSelection:000000277 EndSelection:000000277 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><body><!--StartFragment-->hello <b>world</b><!--EndFragment--></body></html> ]]></pre> See format specification here: [http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/clipboard/htmlclipboard.asp][9]
See also:
Class ClipboardHelper© West Wind Technologies, 2016-2024 • Updated: 11/23/21
Comment or report problem with topic