Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Protect/Unprotect Word Document in C#
// Load Word document
Document doc = new Document("Document.docx");
string password = "123456";
// Protect with a protection type and password
doc.Protect(ProtectionType.ReadOnly, password);
// Save the document
doc.Save("Protected Document.docx");
// Load Word document
Document doc = new Document("Document.docx");
// Protect with a protection type
doc.Protect(ProtectionType.AllowOnlyComments);
// Save the document
doc.Save("Protected Document.docx");
// Load Word document
Document doc = new Document("Protected Document.docx");
// Unprotect Word document
doc.Unprotect();
// Save the document
doc.Save("Unprotected Document.docx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment