Aspose.words working whith open xml WordprocessingDocument object

hi,

i have a program to generate docx file . i am usting both openxml and aspose.words .
i use open xml api to generate docx file and use aspose.words to calculate page count by the below api document.PageCount.

my testing codes as below:

var fileFullname = @“O:_labcal\docs\abc.docx”;
using var wordprocessingDocument = WordprocessingDocument.Open(fileFullname, true);
var stream = new MemoryStream();
wordprocessingDocument.Clone(stream);
var document = new Aspose.Words.Document(stream);
var pageCount = document.PageCount;

when i ran the above codes ,i got the below error:

Aspose.Words.FileCorruptedException:“The document appears to be corrupted and cannot be loaded.”
​ : ZipEntry::ReadDirEntry(): Bad signature (0x00000000) at position 0x00004A3D

can you please help me?

thank you.

@vs6060_qq_com
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25196

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@vs6060_qq_com When use wordprocessingDocument.Clone(stream); position of the resulting stream is at the end. To read the document position must be at the beginning of the stream. Close as not a bug.
Please use the following code:

var stream = new MemoryStream();
wordprocessingDocument.Clone(stream);
stream.Position = 0;
var document = new Aspose.Words.Document(stream);

your codes work very well.
thank you very much.

1 Like

The issues you have found earlier (filed as WORDSNET-25196) have been fixed in this Aspose.Words for .NET 23.4 update also available on NuGet.