Question

I try to add pictures in a autotext with the openxml sdk, the problem now is that i can add the autotexts but the pictures cannot currently be displayed. That has something to do with the relationship id´s, but when i try to add the picture with the same id from the original template, i get the error that the current id is already in use.

to add the pictures i try the following code:

foreach (DocumentBinaryPart relatedDocumentPart in AutotextContainer.RelatedDocumentParts.Where(x => x.Type == "ImagePart"))
     {
        XmlDocument document = new XmlDocument();
        ImagePart imagePart = glossaryDocument.AddImagePart(relatedDocumentPart.ImageType, relatedDocumentPart.relationshipid);

        using (Stream stream = new MemoryStream(relatedDocumentPart.Data))
        {
           imagePart.FeedData(stream);
        }
mainDocumentPart.GlossaryDocumentPart.GlossaryDocument.Save();
Was it helpful?

Solution

I think after the Save() you should call the Close() method. That should hopefully fix it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top