how to find password protected word file

Posted by Santosh4u under C# on 11/22/2013 | Points: 10 | Views : 1563 | Status : [Member] | Replies : 1
Hello friends,

please help me out to rectify the below issue.
how do i check/remove password from the word file which is password protected/encrypted..

programmatically i am trying to open the word files from a folder and doing the process but password protected files are poping up a a windows to enter the password and it's keep opening until user enter the password and not moving to next file.but i want skip those files/remove password which having password protected so that it will move to next file and do the process.

Code :
Microsoft.Office.Interop.Word.Document docs;
Microsoft.Office.Interop.Word.Document docs;
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.ApplicationClass();
object miss = System.Reflection.Missing.Value;
object path = file;
docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);



Posted by: Ring on: 12/6/2013 [Member] Starter | Points: 25

Hi, try the code
Application word = new Application();
word.DisplayAlerts = WdAlertLevel.wdAlertsNone;
word.Documents.OpenNoRepairDialog(@"c:\testfolder\Doc2.docx", ReadOnly: true, PasswordDocument: "RandomButSurelyNotRightPassword");
word.ActivePrinter = "TIFF Image Printer 10.0";
Doc.PrintOut(); //printout untested for now

catch (System.Runtime.InteropServices.COMException ex)
if (ex.ErrorCode == 0x12345678)
//skip file and log file name and position for review

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response