title: Open Word document, unless it has password with C#
body: <p>The thing i am trying to do is run through folders of word documents and convert them to .tif files using a tiff printer in word. The problem is, if i run into a document, with a password it should skip the document without prompting to ask for password, it should all remain in background.</p>
  
  <p>I can see that the Document class have a HasPassword property, but it cannot be checked before the document is opened.</p>
  
  <pre><code>word.Documents.OpenNoRepairDialog(@"c:\testfolder\testDocWithPw.docx", ReadOnly: true);
  </code></pre>
  
  <p>I also tried to give password a emtpy parameter, to and try to catch a errorcode. But i have to press cancel to the prompt asking for password to ever get there.</p>
  
  <pre><code>Application word = new Application();
  word.DisplayAlerts = WdAlertLevel.wdAlertsNone;
  try
  {
      word.Documents.OpenNoRepairDialog(@"c:\testfolder\Doc2.docx", ReadOnly: true, PasswordDocument: "");
      word.ActivePrinter = "TIFF Image Printer 10.0";
      Doc.PrintOut(); //printout untested for now
      Doc.Close(false);
  }
  catch (System.Runtime.InteropServices.COMException ex)
  {
      if (ex.ErrorCode == 0x12345678)
      {
          //skip file and log file name and position for review
      }
  }
  </code></pre>
  
  <p>Thx in advance</p>
  
  <p>EDIT: Just tried to feed the password with wrong password, and i could use the errorcode part, and the best part is that, when there no password it will open the file even if u give it a password. So it basically does what i want.
  In worse case, that i guess someones password on a document that i shouldn't have opened, i can check on the hasPassword property, if i shouldn't have access to a poorly passworded document.</p>