Programmatically changing 'OleFormat.OleIcon = true' not working

I used the following code to change the OleIcon parameter to true for each embedded object. But there is no success. What is the reason? Is there any way to do this? I need this urgently. Please find the attached document (wordattached.doc).
Thank in advance.

Document asposeDoc = new Document(sourceFile, LoadFormat.Doc, "");
NodeList shapeNodeList = asposeDoc.SelectNodes("//Shape");
foreach(Node ole in shapeNodeList)
{
    if (ole is Aspose.Words.Drawing.Shape && ((Aspose.Words.Drawing.Shape) ole).OleFormat != null)
    {
        ((Aspose.Words.Drawing.Shape) ole).OleFormat.OleIcon = true;
    }
}
asposeDoc.UpdateFields();
asposeDoc.Save(destinationFile, SaveFormat.Doc);
}

Note that there is no problem Docx.

Hi

Thanks for your request. I suppose you have attached the document after processing it using this code. Could you please attach your source document here for testing? I will investigate the issue and provide you more information.
Best regards.

Now, please use the code as follows

Document asposeDoc = new Document(sourceFile, LoadFormat.Docx, "");
NodeList shapeNodeList = asposeDoc.SelectNodes("//Shape");
foreach(Node ole in shapeNodeList)
{
    if (ole is Aspose.Words.Drawing.Shape && ((Aspose.Words.Drawing.Shape) ole).OleFormat != null)
    {
        ((Aspose.Words.Drawing.Shape) ole).OleFormat.OleIcon = true;
    }
}
asposeDoc.UpdateFields();
asposeDoc.Save(destinationFile, SaveFormat.Doc);

Hi

Thank you for additional information. I think you should also specify an icon, which will be shown. Please see the following code:

Document doc = new Document(@"Test208\WordAttached.docx", LoadFormat.Docx, "");
NodeCollection shapeNodeList = doc.GetChildNodes(NodeType.Shape, true);
foreach(Shape ole in shapeNodeList)
{
    if (ole.OleFormat != null)
    {
        ole.OleFormat.OleIcon = true;
        // Here you should set icon that will be shown.
        // I set the same icon for all embedded objects, but you can set different iconts
        // depends on OLE object type.
        ole.ImageData.SetImage(@"Common\test.jpg");
    }
}
doc.Save(@"Test208\out.doc");

Hope this helps.
Best regards.

It is not working. Please use my docx as example.

Hi

I used your DOCX file for testing. And as I can see all works as expected. I attached input and output documents. Code is the same, I provided in my previous post.
Also, as, I can see, your DOCX document was created using some third party tool, because all embedded OLE objects has the same ProgId:

<w:object w:dxaOrig="1440" w:dyaOrig="1125">
	<v:shape id="image01" style="width:72.01pt;height:56.31pt" o:ole="">
		<v:imagedata r:id="Rc6a74afd51fa4347" o:title="" />
		<w10:bordertop type="single" width="4" />
		<w10:borderleft type="single" width="4" />
		<w10:borderbottom type="single" width="4" />
		<w10:borderright type="single" width="4" />
	</v:shape>
	<o:OLEObject Type="Embed" ProgID="Package" ShapeID="image01" ObjectID="image01" DrawAspect="Icon" r:id="Re346670ef4334ef0" />
</w:object>

Best regards.

Thank for response.
In out.doc file you attached does not really have a DrawAspect=“Icon”. This can be proved by calling following code.

Document doc = new Document(@"Test208\out.doc", LoadFormat.Docx, "");
NodeCollection shapeNodeList = doc.GetChildNodes(NodeType.Shape, true);

foreach(Shape ole in shapeNodeList)
{
    if (ole.OleFormat != null)
    {
        if (!ole.OleFormat.OleIcon)
        {
            // Here we come only if OleIcon is false. i.e, only
            // if DrawAspect is "Content".
            // But for out.doc we come to here every times
        }
    }
}

Thank for response.
In out.doc file you attached does not really have a DrawAspect=“Icon”. This can be proved by calling following code.

Document doc = new Document(@"Test208\out.doc", LoadFormat.Doc, "");
NodeCollection shapeNodeList = doc.GetChildNodes(NodeType.Shape, true);

foreach(Shape ole in shapeNodeList)
{
    if (ole.OleFormat != null)
    {
        if (!ole.OleFormat.OleIcon)
        {
            // Here we come only if OleIcon is false. i.e, only
            // if DrawAspect is "Content".
            // But for out.doc we come to here every times
        }
    }
}

Hi

Thank you for additional information. I linked your request to the appropriate issue. You will be notified as soon as this problem is resolved.
Best regards.

Hi,
As it turns out programmatically changing OleFormat.OleIcon (e.g. DrawAspect) in Aspose.Words will never work because it requires the host OLE application to display the OLE object in the requried way.
To eliminate confusion, in the next version of Aspose.Words I am making OleFormat.OleIcon readonly.

The issues you have found earlier (filed as 7946) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.