can not copy the inlinshape to the Clipboard in vsto RRS feed

  • Question

  • vs2012, office2013

    i have three RichTextContentControl in my document,we name it A,B,C. and  i subscription the vstoDocument_BeforeSave event...

    first,  the A RichTextContentControl  have a picture, i cut the picture to RichTextContentControl B by UI action

    when i save the document, i use the below code to looping through all shape in the document

      foreach (Word.ContentControl c in vstoDocument.ContentControls) {
                    if (c.Type == Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlRichText) {
                        if (c.Range.InlineShapes != null && c.Range.InlineShapes.Count > 0) {
                            foreach (Word.InlineShape s in c.Range.InlineShapes) {
                                object obj = Clipboard.GetData(System.Windows.Forms.DataFormats.Bitmap);

    i can find the picture in RichTextContentControl B, but there's a strange problem, the "obj" in code will be null, i can't understand the reason.

    and i try change my behavior: cut the picture to RichTextContentControl A but not in the origin paragraph, the code will be ok. why?

    Help please! 

    Thanks will

    Friday, September 27, 2013 1:21 PM


  • i found the way by myself, use the appliction.selection.copy() other than shape.range.copy() method.

    foreach (InlineShape shape in item.Range.InlineShapes)


        if (shape.Type == WdInlineShapeType.wdInlineShapePicture)




            if (Clipboard.ContainsImage())


                Bitmap bmp = new Bitmap(Clipboard.GetImage());

                fileName = System.Guid.NewGuid() + defaultPicExtension;

                bmp.Save(savePath + fileName, System.Drawing.Imaging.ImageFormat.Png);




    • Marked as answer by sendreams Saturday, September 28, 2013 2:08 PM
    Saturday, September 28, 2013 2:08 PM