none
Possible to paste base64 encoded embedded images from clipboard? RRS feed

  • Question

  • I have an application that inserts various things in existing Word documents via Interop. This is done by creating a string containing the data in CF_HTML format, setting it on the clipboard and then pasting it with Interop calls (to be more specific, it is pasted with _application.Selection.PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting);).

    This works with most things I tested, but it seems like it doesn't work with images that are embedded in the HTML code by a Data URI scheme. I'm trying to insert the following clipboard content:

    Version:1.0
    StartHTML:0000000105
    EndHTML:0000000426
    StartFragment:0000000228
    EndFragment:0000000394
    <html xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns="http://www.w3.org/TR/REC-html40"><body><!--StartFragment--><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" /><!--EndFragment--></body></html>
    

     

    Is there any way to insert an image this way? If possible, I'd like to not have to create temporary files for pasting.

    Wednesday, April 6, 2011 1:57 PM

All replies

  • Hello cremor,

    There is no immediately available body of knowledge that tells you how to bypass the image file. You can look further into this by navigating to http://msdn.microsoft.com/en-us/library and in the search box key the search query "base64" (without the quotes.) You'll see the first 20 of 24,500 hits. On the first page see the article ""convert.tobase64String Method(Byte[])(System)"

    In the next 20 see the article " XnlWriter.WriteBase64 Method"

    Since the purpose of base64-bit encoding is to convert a binary string to a string that uses only the first 76 ascii characters you may find it is more straightforward to not use the clipboard but deal directly with the base64-bit encodded string itself.

    Chris Jensen
    Senior Technical Support Lead

    Friday, April 8, 2011 6:16 PM
    Moderator