Free Support Forum -

Determining if a Word document is password protected before uploading the file


I am working on a website, which allows users to upload different file formats. We need to restrict the user from uploading password protected files.

Is there a way to determine if a Microsoft Office file (Word, Powerpoint & Excel) is password protected before uploading the file?


Hi Sunita,

Thanks for your inquiry.

Aspose.Words provides the facility to open password protected Word files. The best way to check if a Microsoft Office Word file is password protected or not is to load the file using Aspose.Words normally and if you receive a Aspose.Words.IncorrectPasswordException then it is password protected file. As for other formats, such as Powerpoint & Excel, Aspose.Words only supports DOC, DOCX, RTF, HTML, OpenDocument, PDF, XPS and EPUB so you cannot use Aspose.Words to load and check Powerpoint or Excel documents. For Powerpoint you can look into Aspose.Slides and for Excel Aspose.Cells should be a good option to start with.

For checking Microsoft Word documents using Aspose.Words, following code snippet can help you:

String csInputFilePath = "complete uploaded file path";
         #2B91AF">Document doc = new Document(csInputFilePath);<o:p></o:p>
catch (Aspose.Words.IncorrectPasswordException icPasswordException)<o:p></o:p>
         MessageBox.Show(“Document is password protected, please make sure to provide password.”);<o:p></o:p>
<span style=“font-family:“Arial”,“sans-serif”;

Hope this helps. Please let us know if you need any further assistance.

I am not actually using Aspose Words library, and am looking for some code using Microsoft libraries.

Could you tell me what is used by Aspose Words Library, to determine whether the file is password protected?

Hi Sunita,

Thank you for your interest in Aspose products. I would receommend you to use Powerful Aspose products for this purpose. As for the code using Microsoft liibraries go, you can ask the experts here

Hope this helps. Please let us know if you need more assistance, we will be glad to help you.