Free Support Forum - aspose.com

Password protected docm- dotm recognized as docx

Hi,


I use this code to determine file type:
FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + “Document.doc”);
Console.WriteLine("The document format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat));
Console.WriteLine("Document is encrypted: " + info.IsEncrypted);
But when I tried to detect file type for password protected docm and dotm - I received following:
The document format is: .docx
Document is encrypted: True

Is it correct behavior?
docm and dotm without password protection are identified fine.

Thank you,
Alex Shloma

Hi Alex,


Thanks for your inquiry. The FileFormatUtil.DetectFileFormat detects and returns the information about a format of a document stored in a disk file.

Even if this method detects the document format, it does not guarantee that the specified document is valid. This method only detects the document format by reading data that is sufficient for detection. To fully verify that a document is valid you need to load the document into a Document object.

Hope this answers your query. Please let us know if you have any more queries.

Hi Tahir,


I do not need to check if document is valid (“it does not guarantee that the specified document is valid”). I just need to detect document format.
This method only detects the document format by reading data that is sufficient for detection. To fully verify that a document is valid you need to load the document into a Document object.” - I have issue that both (FileFormatUtil.DetectFileFormat and doc.OriginalLoadFormat) returns .docx for password protected docm, dotm, dotx. For all others cases all works as expected. When document in OpenXML format is password protected - Aspose always says that this is docx format.

Thank you,
Alex Shloma

Hi Alex,


Thanks for sharing the detail. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-7901 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Tahir,


Many thanks for your assistance.

Best regards,
Alex Shloma

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


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

Thanks. Now works properly.


Best regards,
Alex Shloma

Hi Alex,


Thanks for your feedback. Please note that FileFormatUtil.DetectFileFormat detects and returns the information about a format of a document stored in a disk file.

If you use the following code, the FileFormatInfo.LoadFormat return Docx because the document is encrypted. For an encrypted OOXML document, it is not possible to ascertained whether it is an Docm, Docx, Dotm.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>FileFormatInfo<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> info = FileFormatUtil.DetectFileFormat(MyDir + “passProtected.docm”);<o:p></o:p>

Console.WriteLine(info.LoadFormat); // info.LoadFormat return Docx because the document is encrypted.


So, in this case, the Document.OriginalLoadFormat Property will return correct file format.


LoadOptions loadoption = new LoadOptions();

loadoption.Password = "test";

Document doc = new Document(MyDir + "passProtected.docm", loadoption);

Console.WriteLine(doc.OriginalLoadFormat.ToString()); // This will return docm.





Thank you for explanations!


Best regards,
Alex Shloma

Hi Alex,


Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.