Monday, 2 September 2013

Open XML SDK - AddImagePart - Change image location from /media to /word/media

Open XML SDK - AddImagePart - Change image location from /media to
/word/media

I am trying to insert an image into a document from C# using the Open XML
SDK 2.5. The document is subsequently going to be uploaded to Google Drive
and converted to a Google Document.
I am currently using the MainDocumentPart.AddImagePart method which
inserts the image into the /media folder of the file hierarchy. However,
Drive only wants to read the image if it is located in the /word/media
folder.
Opening the document in Microsoft Word and saving it again relocates the
image to the /word/media folder (and updates the part relationships), and
thus makes Drive able to read the image, but the file is not going to be
edited in Word before being uploaded to Drive.
Is there any way to place the image in the /word/media folder, short of
closing the file in Open XML SDK, opening it up as a zip-archive,
relocating the images and updating the relationships manually?

No comments:

Post a Comment