Differentiate Between InPlace and Attachment in RTF

Is there any way to differentiate between In place and Attached RTF?

Attaching the samples

Hi Yuva,

Thanks for your inquiry. Could you please share some more detail about your query what exact you want to achieve by using Aspose.Words? We will then provide you more information about your query along with code.

OleFormat class provides access to the data of an OLE object or ActiveX control. Use the OleFormat property to access the data of an OLE object. You do not create instances of the OleFormat class directly. Please read the members of OleFormat class from here:
https://reference.aspose.com/words/net/aspose.words.drawing/shape/oleformat/

In “Inplace.rtf”, there is a excel object which u can see content as inline.
In “Attached.rtf”, there is a PDF object which is displayed as Icon.

How can I differentiate between the above two. For both, I observed OleFormat.OleIcon is false.

Hi Yuva,

Thanks for sharing the detail. Your both documents are embedded object not linked object. The OleFormat.IsLink property returns true if the OLE object is linked (when SourceFullName is specified). Please use OleFormat.SourceFullName Property to get or set the path and name of the source file for the linked OLE object.

Your documents do not display the embedded object as Icon. OleFormat.OleIcon property get the draw aspect of the OLE object. When true, the OLE object is displayed as an icon. When false, the OLE object is displayed as content. https://reference.aspose.com/words/net/aspose.words.drawing/shape/oleformat/

I hope you didn’t understand my query clearly. I am not asking about OleFormat.IsLink.

I know that both are embedded objects. But what I am trying to say is one object is displayed as Icon and excel is displayed as viewable content. Just open and see it you will get idea what I am trying to say…

Also attached a sample image. How can I differentiate between them?

Hi Yuva,

Thanks for sharing the
detail. You can use OleFormat.IsLink and OleFormat.OleIcon to achieve your requirements. Please note that when you insert Excel document in Word document which is neither ‘link to file’ nor ‘display as icon’ will be shown as shared in Inplace.rtf. In this case, the value of OleFormat.IsLink and OleFormat.OleIcon is false. See the attached image for detail.

When you insert the Pdf file with same setting in MS Word document, it will be shown as shared in Attached.rtf. In this case, the value of OleFormat.IsLink and OleFormat.OleIcon is false.

Please check the values of OleFormat.IsLink and OleFormat.OleIcon for attached in.docx using following code example. Hope this answers your query. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");

foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
    if (shape.OleFormat != null)
    {
        Console.WriteLine(shape.OleFormat.IsLink);
        Console.WriteLine(shape.OleFormat.OleIcon);
        Console.WriteLine(shape.OleFormat.SuggestedExtension);
        Console.WriteLine("----------------------------------------");
    }
}