Replace image in word doc using OpenXML

Posted by fearofawhackplanet on Stack Overflow See other posts from Stack Overflow or by fearofawhackplanet
Published on 2010-05-11T11:13:55Z Indexed on 2010/05/14 12:34 UTC
Read the original article Hit count: 407

Filed under:
|
|

Following on from my last question here

OpenXML looks like it probably does exactly what I want, but the documentation is terrible. An hour of googling hasn't got me any closer to figuring out what I need to do.

I have a word document. I want to add an image to that word document (using word) in such a way that I can then open the document in OpenXML and replace that image. Should be simple enough, yes?

I'm assuming I should be able to give my image 'placeholder' an id of some sort and then use GetPartById to locate the image and replace it. Would this be the correct method? What is this Id? How do you add it using Word?

Every example I can find which does anything remotely similar starts by building the whole word document from scratch in ML, which really isn't a lot of use.

EDIT: it occured to me that it would be easier to just replace the image in the media folder with the new image, but again can't find any indication of how to do this.

© Stack Overflow or respective owner

Related posts about openxml

Related posts about .NET