Hi Martin,
Thank you for contacting Syncfusion support.
From the given details, we have found that your requirement is to find whether the given document is password protected or not. If the password protected document is trying to open using DocIO without password, the exception will throw from our source like below.
|
Document is encrypted, password is needed to open the document |
Based on this exception we can find the given document is password protected or not and we can get the password and again reopen the document with password as like below.
|
WordDocument document = null; try { document = new WordDocument(@"input.docx", FormatType.Docx); } catch (Exception ex) { if (ex.Message == "Document is encrypted, password is needed to open the document") { string password = "password"; document = new WordDocument(@"input.docx", FormatType.Docx, password); document.Save("output.docx"); document.Close(); } } |
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran