Aspose.Words Support

Hi,
I am working on one of the requirement to identify the embedded file and file type in WORD document. I am not able to find sample code. Can you please give your direction how to achieve this. I have attached 5 documents in WORD document. I need to get the collection of those attached documents and find the file type.

Hi Ganesh,

Thanks for your inquiry. Please use the following code example to extract OLE embedded Package. Hope this helps you. If you still face problem, please share your input Word document here for our reference. We will then provide you more information on this.

// Open document
Document doc = new Document(MyDir + "in.docx");
// OLE embedded objects are available through OleFormat property of Shape object
// So first we should extract shapes from the document
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
// Index will be used to generate unique name for each extracted object
int oleIndex = 0;
// Define variable that specifies base path
string basePath = MyDir + "obj_{0}.{1}";
// Loop through all shapes
foreach (Shape shape in shapes)
{
    // Check whether shape contains OLE object
    if (shape.OleFormat != null)
    {
        // We can determine type of an OLE object using ProgId property
        switch (shape.OleFormat.ProgId)
        {
            // ZIP archive ProgId = Package
            case "Package":
                shape.OleFormat.Save(String.Format(basePath, oleIndex, "zip"));
                break;
            // DOC files
            case "Word.Document.8":
                shape.OleFormat.Save(String.Format(basePath, oleIndex, "doc"));
                break;
            // DOCX files
            case "Word.Document.12":
                shape.OleFormat.Save(String.Format(basePath, oleIndex, "docx"));
                break;
            // By default let's save OLE object with .object extension
            default:
                shape.OleFormat.Save(String.Format(basePath, oleIndex, "object"));
                break;
        }
        // Increase index
        oleIndex++;
    }
}

Thank you so much… It works like charm…

Thanks for your support. Its working…

Hi Ganesh,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.