Creating an Embedded OLE Object is blocked by office and Aspose Icon is shown in place of content

Hi Team,

I’m embedding an word object into an word object, and when saved into a main document, I’m seeing a Aspose Image in place of content. Also when I double click on it I’m seeing office blocked error, though I have cleared all the save settings under trust center settings.

Attaching the console app for more clarity.
OleObjects.zip (97.7 KB)

child.docx (19.3 KB)

main.docx (19.1 KB)

Thanks,

@kaushlendu.choudhary The behavior is expected. First of all in your code incorrect ProgId is specified. You should use Word.Document.12. Also, you specified flag display as icon to false but do not provided a presentation image for the OLD object. So Aspose.Words uses a default image. You can try modifying your code like this:

Document mainDoc = new Document(@"C:\Temp\Main.docx");
DocumentBuilder builder = new DocumentBuilder(mainDoc);

// Load the document to be inserted as an OLE object
byte[] oleObjectData = File.ReadAllBytes(@"C:\Temp\child.docx");
// Create presentation image
byte[] presentationImage = null;
using (MemoryStream docStream = new MemoryStream(oleObjectData))
{
    Document childDoc = new Document(docStream);
    // Save the child doc as an image.
    using (MemoryStream presentationStream = new MemoryStream())
    {
        childDoc.Save(presentationStream, new ImageSaveOptions(SaveFormat.Emf));
        presentationImage = presentationStream.ToArray();
    }
}

// Insert the OLE object
Shape oleObject = builder.InsertOleObject(
    new MemoryStream(oleObjectData),  // Stream of the OLE object
    "Word.Document.12",  // ProgID
    false,  // Display as icon
    new MemoryStream(presentationImage)  // Presentation image
);

// Save the main document
mainDoc.Save(@"C:\Temp\out.docx");

Note the presentation image might require preprocessing. The code shows only the basic technique.

Hi @alexey.noskov

How can I see the refreshed data in the mainole doc, if I do changes in child doc.

As per above code it seems we’re getting the static/current data from the child doc and pasting it as ole object which cannot be refreshed if any changes are done to child doc.

Is there a way to achieve, the objects functionality as this Embed or link to a file in Word - Microsoft Support

@kaushlendu.choudhary Updating the image after updating of the embedded document in MS Word is out of Aspose.Words control. After updating the embedded document, MS Word should automatically update the representation image.