Contents problems when saving document in Docm format

Hi!
I have a service that is using Aspose.Words ver. 11.7.0 to create Docm documents. The service uses the Document constructor to open the template that contains macros with the LoadFormat set to Dotm. After replacing of bookmarks, the new document is created and saved in docm format. When I then try to open that document the following error is displayed: “The file xxxxx cannot be open because there are problems with the contents.” Details: The file is corrupt and cannot be opened.
Regards
DSGI

Hi,

Thanks for your inquiry. Could you please attach your input document here for testing? I will investigate the issue on my side and provide you more information.

Best Regards,

Hi!
Here it is. Thank you.
Regards,
dsgi

Hi,

Thanks for your inquiry.

While using the latest version of Aspose.Words for .NET i.e. 11.7.0, I was unable to reproduce this issue on my side. I would suggest you please upgrade to the latest version of Aspose.Words. You can download it from the following link:
https://releases.aspose.com/words/net

Also, I used the following code to check your scenario:

Document dotm = new Document(@"c:\test\template.dotm", options);
dotm.Range.Bookmarks.Clear();
MemoryStream docmStream = new MemoryStream();
dotm.Save(docmStream, SaveFormat.Docm);
Document docm = new Document(docmStream);
docm.Save(@"c:\test\out.docm");

Please let me know if I can be of any further assistance.

Best Regards,

Hi,

Could you please also double check if you are using the latest version (11.7.0)? You can dynamically check if you’re referencing the correct DLL by using the following code snippet:

System.Reflection.Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach(System.Reflection.Assembly assembly in assemblies)
{
    System.Reflection.AssemblyName assemblyName = assembly.GetName();
    if (assemblyName.Name.Contains("Aspose.Words"))
        Console.WriteLine("Aspose.Words Version Number: " + assemblyName.Version.ToString());
}

If we can help you with anything else, please feel free to ask.

Best Regards,

The version I’m using is the latest version: 11.7.0.
I have tested some more and the result is that the Save method that stores to a Stream (that I’m using) is different from the Save method that stores to a file. After reading the file into a byte array and comparing it with the Stream, they have different size.
Regards,
dsgi

Hi,

Thanks for the additional information.

Regarding your first problem i.e. Aspose.Words.FileCorruptedException, did you manage to fix the issue on your side or are you still in need of assistance?

Regarding the document size problem, could you please share the code here for testing. I will investigate the issue on my side and provide you more information.

Best Regards,