The following code throws when I load the attached document. Aspose.Word v20.4.
var doc = new Aspose.Words.Document(inputStream);
doc.Save(outputStream, Aspose.Words.SaveFormat.Docx);
Instruction.doc.zip (34.3 KB)
I have no idea what’s wrong with this document.
@volozyko,
What exception are you observing on your end? Please share the exception message. When converting this DOC to DOCX format, we see that the Save method throws the following exception on our end:
System.InvalidOperationException
HResult=0x80131509
Message=This document contains macros (VBA project) and you are attempting to save it in a Macro-Free format. Such document will be invalid if created. You need to either save it in a Macro-Enabled format (.DOCM or .DOTM) or remove macros before saving using the Document.RemoveMacros method.
Source=Aspose.Words
You can either save to DOCM format or remove macros before saving to DOCX format:
Document doc = new Document("E:\\Temp\\instruction\\Instruction.doc");
if (doc.HasMacros)
{
doc.RemoveMacros();
using (MemoryStream outputStream = new MemoryStream())
{
doc.Save(outputStream, SaveFormat.Docx);
outputStream.Position = 0;
}
}
Thanks for the hint. The problem is gone.
So, I suppose the exception was related to the macros. Sorry, I cannot say anything more. In my program I have to invoke .Net code from C++ (don’t ask why - it has a long history) and in this setup I cannot natively debug .Net code. Basically I know there is an exception but what kind of exception is difficult to say normally.
@volozyko,
It is great that you were able to fix the problem on your end. Please let us know any time you may have any further queries in future.