Document.Save not saving document in Word 2010 .dotm format

Hi,
I have an ASP.NET application that uses Aspose.Words to create Microsoft Word documents. We recently upgraded to Office 2010 and now I want my application to create documents in Word 2010 format.
The application generated documents from macro enabled templates and I have converted all of them to Word 2010 .dotm format. I have also updated the application code that creates the documents to save them with an extension of .docm and I do specify .docm as the file format in the Save command.
This all seems to work fine. The ASP.NET application has a page with links on it to various documents that the users can click on and have the document open in Word 2010. The links are displayed in a datagrid. When this page is first loaded, as each item in the datagrid is databound, the user’s role is checked and the protection of the document is updated to allow only specific users to update the document. If the user is not allowed to update the document, it is opened in protected, read-only mode. Here is the code snippet from the ITEMDATABOUND event of the datagrid that does this:

If InStr(CType(e.Item.FindControl("txtFileName"), TextBox).Text, ".docm") Then
Dim strFilePath as String = CType(e.Item.FindControl("txtFileName"), Textbox).Text)
Dim doc As Document = New Aspose.Words.Document(strFilePath)
If Session("StaffRole") = "PA" Then
doc.Protect(ProtectionType.NoProtection)Else
If CType(e.Item.FindControl("chkFinal"), System.Web.UI.WebControls.CheckBox).Checked = True Then
doc.Protect(ProtectionType.ReadOnly, "AMSDOC")
Else
doc.Protect(ProtectionType.NoProtectionEnd If
End If
doc.Save(strFilePath, SaveFormat.Docm) <== This statement
End If

The problem is that the statement marked above doesn’t seem to be saving the documents as 2010 .docm files because when I open the documents they open in Word 2010 in compability mode. If I run the templates outside of the ASP.NET application and create documents directly in Word 2010, everything is fine – no compability mode. It’s only when the above DOC.SAVE command is executed that the documents subsequently open in compability mode.
I tried commenting out the above doc.save statement and the documents subsequently opened cleanly not in compatibility mode. The documents are definitely saved as .docm files. When I go into the folder on the network drive where they are stored, they are listed as Microsoft Word Macro-Enabled Documents. But, I understand that Word 2007 also has macro-enabled .docm files and that the format is different from Word 2010 and that if you open a Word 2007 .docm document in Word 2010 it will open in compatibility mode.
Is the SaveFormat.Docm parameter of the Document.Save command for the Word 2007 .docm format? Is there another parameter value I should be using for Word 2010?
Thanks very much for any help you can give.
C.

Hi
Chris,

Thanks for your inquiry. Could you please try using OoxmlSaveOptions.Compliance property for specifying the OOXML version for the output DOCM document? The default value is Ecma376_2006. Instead, please try using the following code and let us know how it goes on your side:

Document doc = new Document(@"Test001\in.docx");

OoxmlSaveOptions opt = new OoxmlSaveOptions(SaveFormat.Docm);
opt.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;

doc.Save(@"Test001\out.docm", opt);

I hope, this will help.

Best Regards,

Thank you for your reply, Awais.
When I added the code as you suggested, Visual Studio tells me that OoxmlSaveOptions and OoxmlCompliance are not defined.
I import the Aspose.Words namespace at the top of my code but obviously it doesn’t contain OoxmlSaveOptions and OoxmlCompliance. Is there another namespace I need to import?
Thanks again!
C.

Hi Chris,

Thanks for your inquiry. Please import ‘Aspose.Words.Saving’ by using namespace-directive. Please let me know if I can be of any further assistance.

Best Regards,

Thanks again for the quick response, Awais.
Importing the Aspose.Words.Saving namespace solved the problem. My documents are now being saved in Word 2010 .docm format and are no longer being opened in compatibility mode.
I greatly appreciate your help.
C.

Hi Chris,

It’s great that you managed to resolve the problem on your side. Please let us know any time you have any further queries. We are always glad to help you.

Thanks Imran!
Actually, I am now having a problem declaring an Aspose.Words document object based on an existing document file. I have the following VB code:

If InStr(strFilePath, ".doc") Then
Dim doc As Document = New Aspose.Words.Document(strFilePath)
End If

The variable “strFilePath” contains the full pathname of an existing Word document. I wish to access this document and manipulate it in code, but the DIM statement is failing with the message: Unknown File Format.
Any help you can give will be greatly appreciated!
Thanks!

Hi Chris,

Thanks for the inquiry. Could you please share your input document here? We’ll take a closer look and guide you accordingly.

Thanks Imran. The problem seems to have solved itself for now. Everything is working fine again. I will check with my system administrator. Maybe they were doing something earlier that might have caused the problem.
Thanks again for your quick response.
C.

Hi Chris,

It’s great that you managed to resolve the problem on your side. Please let us know any time you have any further queries. We are always glad to help you.

Thanks again, Imran!
Actually, I have tracked the problem down further and it appears that using the Visual Studio FILE object to copy and move documents created by Aspose.Words in Word 2010 .docm format is causing the documents to be emptied of their contents.
You can try and re-create the problem using Awais’s code snippet from a previous post above:

Document doc = new Document(@"Test001\in.docx");
OoxmlSaveOptions opt = new OoxmlSaveOptions(SaveFormat.Docm);
opt.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;
doc.Save(@"Test001\out.docm", opt);

First, try creating and saving a document in Word 2003 format:

Document doc = new Document(@"Test001\in.dot");
doc.Save(@"Test001\out.doc");

Make sure in.dot and out.doc have text inside them.
Now, use the File object in Visual Studio to make a copy of the document:

File.Copy(@"Test001\out.doc",@"Test001\out-copy.doc");

Open out-copy.doc. Its contents should be visible and should be identical to out.doc.
Now, try the same thing only with documents in “.docm” format:

Document doc = new Document(@"Test001\in.dotm");
OoxmlSaveOptions opt = new OoxmlSaveOptions(SaveFormat.Docm);
opt.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;
doc.Save(@"Test001\out.docm", opt);

Again, make sure in.dotm and out.docm have text in them.

File.Copy(@"Test001\out.docm",@"Test001\out-copy.docm");

Open out-copy.docm and out.docm. When I do this both documents are blank (ie. their contents have been erased).
Any ideas? My apologies for any syntax issues – I code in VB and my C# is a little rusty.
Thanks again for all your help.
C.

Hi Chris,

Thanks for the additional information. While using the latest version of Aspose.Words i.e. 11.3.0 with .Net Framework 4.0, I was unable to reproduce this problem on my side. Could you please upgrade to Aspose.Words v11.3.0 and let us know if this problem still occurs? You can download the latest version of Aspose.Words from the following link:
https://releases.aspose.com/words/net

Best Regards,

Hi Awais,
I have downloaded and installed Aspose.Words 11.3.0 as you suggested and my application targets .Net Framework 4.0. Unfortunately, the problem is still occurring. Any help you can give would be greatly appreciated.
Thanks!

Hi Chris,

Thanks for your inquiry and sorry for the delayed response. Unfortunately, I was still unable to reproduce this problem on my side. I have attached the documents, i.e. generated/used on my side, here for your reference. Could you please also attach your input/output Word documents, you’re getting this problem with, here for testing? I will investigate the issue further on my side and provide you more information.

Best Regards,

Thanks Awais. As requested, please find a .zip file attached. There are 4 Word 2010 documents in it:
General-Letter-Shell.dotm - the template used to create the documents
MA10-183-before.docm - the document originally produced by the template, BEFORE the FILE.COPY command was issued
MA10-183.docm - what MA10-183-before.docm became AFTER the FILE.COPY command was issued
MA10-183-COPY-0516120038.docm - the copy of MA10-183 made by the FILE.COPY command
Just FYI, MA10-183.docm is the name of the actual document file in question. Before running the FILE.COPY command in my application, I opened MA10-183.docm in Word 2010 and did File --> SAVE AS and saved it outside my application under the name MA10-183-before.docm so I could show you the original contents of the document before the FILE.COPY command erased them.
Also, I have tried using the FILE.COPY command on “.docm” documents that were produced in Word 2010 (i.e. not using Aspose.Words) and the problem does not occur, i.e. the FILE.COPY command successfully copies “native” Word 2010 documents. It appears to me that the problem only occurs on those documents created by Aspose.Words and saved using the Aspose.Words Document.Save command.
Thanks again for your help.
C.

Hi Chris,

Thanks for the additional information. Could you please create and attach here a simple console application using VS 2010 that enables us to reproduce this issue on our side? I will investigate the issue further and provide you more information. Unfortunately, I couldn’t reproduce this problem on my side. We apologize for your inconvenience.

Best Regards,

Thanks Awais.
I created a simple VS 2010 application as you suggested, only it is a Windows appl rather than a console app because it is easier for me to code it to create and copy the document files as needed.
As it turns out, the Windows app has no problem at all creating and copying Word 2010 .docm files. I even tried putting the Windows app on the web server with my ASP.NET web app (the one that experiences the problem). The Windows app saves the document files to the same network folder that the web app does and both apps use the same impersonation id to connect to the network folder.
Since the Windows app works, but the web app doesn’t work, it seems like this might be an IIS issue. At any rate, this shows that it is not an issue with Aspose.Words, so rather than use up any more of your time, I will close off this discussion thread and try pursuing it in one the Microsoft ASP.NET forums.
Thanks again for all your help on this.
Best regards,
C.

Hi Chris,

Thanks for the additional information. Please let us know any time you have any further queries. We are always glad to help you.

Best Regards,

The issues you have found earlier (filed as WORDSNET-6410) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(3)