How to access ExtendedPart files using Aspose.Words?

Hi,

We sometimes add ExtendedParts to the document for future use. I found it is very easy to access these parts using Open Xml SDK by runnin the following code:

        var wDoc = WordprocessingDocument.Open(@"extendeddata.docx", true);
        var extendedParts = wDoc.GetPartsOfType<ExtendedPart>().ToList();
        var stream = extendedParts[0].GetStream();
        var id = wDoc.GetIdOfPart(extendedParts[0]);
        var fileStream = File.Create(id + ".txt");
        stream.Seek(0, SeekOrigin.Begin);
        stream.CopyTo(fileStream);
        fileStream.Close();
        stream.Close();

Then I could have the external data (in my example it’s a .txt file embedded in the document) extracted with id on its name.

However I didn’t find the equivalent in Aspose.Words. Could you please advise what is the best approach to access this external data file using Aspose?

I’ve attached the docx and the expected output for your reference.

Thanks,
extendeddata.zip (9.0 KB)

@ServerSide527,

We have logged your requirement in our issue tracking system. The ID of this issue is WORDSNET-16631. We will further look into the details of this problem and will keep you updated on the status of this issue.

@ServerSide527,

Regarding WORDSNET-16631, you can do the same by using CustomPart (Represents a custom arbitrary content) part, that is not defined by the ISO/IEC 29500 standard.) More information you can find here:

Please check the following sample code:

Document doc = new Document(MyDir + @"extendeddata\extendeddata.docx");

foreach (CustomPart custPart in doc.PackageCustomParts)
{
    MemoryStream stream = new MemoryStream(custPart.Data);
    string id = custPart.Name;
    var fileStream = File.Create(MyDir + @"abc.txt");
    stream.Seek(0, SeekOrigin.Begin);
    stream.CopyTo(fileStream);
    fileStream.Close();
    stream.Close();
}

Hi,

Thanks for your reply.

I know we could use the code you suggested to retrieve the Data of the part, however it didn’t resolve the part of the question on how to retrieve the Id of the part where it was retrievable in Open Xml Sdk:
( var id = wDoc.GetIdOfPart(extendedParts[0]); in my code)

Could you please advise the equivalent of retrieving the datapart id using Aspose?

Thanks

@ServerSide527,

Please try using the following code:

Document doc = new Document(MyDir + @"extendeddata\extendeddata.docx");

foreach (CustomPart custPart in doc.PackageCustomParts)
{
    MemoryStream stream = new MemoryStream(custPart.Data);
    string[] splits = custPart.Name.Split(new char[] { '/' });
    string id = splits[splits.Length - 1];
    var fileStream = File.Create(MyDir + id);
    stream.Seek(0, SeekOrigin.Begin);
    stream.CopyTo(fileStream);
    fileStream.Close();
    stream.Close();
}

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan