Src/Pscx/Commands/UIAutomation/SetClipboardCommand.cs
/// <summary>
/// Clears the clipboard and copies an HTML fragment to the clipboard, providing additional meta-information.
/// </summary>
/// <param name="htmlFragment">a html fragment</param>
/// <param name="title">optional title of the HTML document (can be null)</param>
/// <param name="sourceUrl">optional Source URL of the HTML document, for resolving relative links (can be null)</param>
Clears the clipboard and copies an HTML fragment to the clipboard, providing additional meta-information.
Clears the clipboard and copies an HTML fragment to the clipboard providing additional meta - information .
public static void CopyHtmlToClipboard(string htmlFragment, string title, Uri sourceUrl)
        {
            StringBuilder sb = new StringBuilder();
            if (title == null)
            {
                title = "From Clipboard";
            }
            string header = @"Format:HTML Format
Version:1.0
StartHTML:<<<<<<<1
EndHTML:<<<<<<<2
StartFragment:<<<<<<<3
EndFragment:<<<<<<<4
StartSelection:<<<<<<<3
EndSelection:<<<<<<<3
";
            string pre =
    @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">
<HTML><HEAD><TITLE>" + title + @"</TITLE></HEAD><BODY><!--StartFragment-->";
            string post = @"<!--EndFragment--></BODY></HTML>";
            sb.Append(header);
            if (sourceUrl != null)
            {
                sb.AppendFormat("SourceURL:{0}", sourceUrl);
            }
            int startHTML = sb.Length;
            sb.Append(pre);
            int fragmentStart = sb.Length;
            sb.Append(htmlFragment);
            int fragmentEnd = sb.Length;
            sb.Append(post);
            int endHTML = sb.Length;
            sb.Replace("<<<<<<<1", To8DigitString(startHTML));
            sb.Replace("<<<<<<<2", To8DigitString(endHTML));
            sb.Replace("<<<<<<<3", To8DigitString(fragmentStart));
            sb.Replace("<<<<<<<4", To8DigitString(fragmentEnd));
            string data = sb.ToString();
            WinFormsClipboard.Clear();
            WinFormsClipboard.SetText(data, TextDataFormat.Html);
        }
public static void CopyHtmlToClipboard ( string htmlFragment , string title , Uri sourceUrl ) { StringBuilder sb = new StringBuilder ( ) ; if ( title == null ) { title = " " ; } string header = @"Format:HTML Format
Version:1.0
StartHTML:<<<<<<<1
EndHTML:<<<<<<<2
StartFragment:<<<<<<<3
EndFragment:<<<<<<<4
StartSelection:<<<<<<<3
EndSelection:<<<<<<<3
" ; string pre = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">
<HTML><HEAD><TITLE>" + title + @"</TITLE></HEAD><BODY><!--StartFragment-->" ; string post = @"<!--EndFragment--></BODY></HTML>" ; sb . Append ( header ) ; if ( sourceUrl != null ) { sb . AppendFormat ( " " , sourceUrl ) ; } int startHTML = sb . Length ; sb . Append ( pre ) ; int fragmentStart = sb . Length ; sb . Append ( htmlFragment ) ; int fragmentEnd = sb . Length ; sb . Append ( post ) ; int endHTML = sb . Length ; sb . Replace ( " " , To8DigitString ( startHTML ) ) ; sb . Replace ( " " , To8DigitString ( endHTML ) ) ; sb . Replace ( " " , To8DigitString ( fragmentStart ) ) ; sb . Replace ( " " , To8DigitString ( fragmentEnd ) ) ; string data = sb . ToString ( ) ; WinFormsClipboard . Clear ( ) ; WinFormsClipboard . SetText ( data , TextDataFormat . Html ) ; }
Clears the clipboard and copies an HTML fragment to the clipboard, providing additional meta-information.
Clears the clipboard and copies an HTML fragment to the clipboard providing additional meta - information .
// Builds the CF_HTML header. See format specification here: // http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/clipboard/htmlclipboard.asp // The string contains index references to other spots in the string, so we need placeholders so we can compute the offsets.  // The <<<<<<<_ strings are just placeholders. We'll backpatch them actual values afterwards. // The string layout (<<<) also ensures that it can't appear in the body of the html because the < // character must be escaped. // Backpatch offsets // Finally copy to clipboard.
htmlFragment
string
a html fragment
a html fragment
title
string
optional title of the HTML document (can be null)
optional title of the HTML document ( can be null )
sourceUrl
Uri
optional Source URL of the HTML document, for resolving relative links (can be null)
optional Source URL of the HTML document for resolving relative links ( can be null )