Search code examples
c#ms-officeoffice-interopms-publisher

Insert image file to publisher document in place of existing image


I have publisher document used as template.

enter image description here

How to insert image from file in place of "?" image.

Probably it's same way as for MS Word but I can't find out.

I access that template this way:

using Publisher = Microsoft.Office.Interop.Publisher;

Publisher._Application pubApp = new Publisher.Application();
Publisher.Document doc = pubApp.Open(docPath);
Publisher.Page templateCard = doc.Pages[1];

Solution

  • Basically:

    shape.PictureFormat.Replace(filePath);
    

    Best way to find my template image I figured out is set alternative text to my image and just chack it:

    foreach (Publisher.Shape shape in currenPage.Shapes) {
        if (shape.AlternativeText == "DICKBUTT")
            //here you do your stuff
    }