Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active February 27, 2020 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/b119c2cc8610cb2f3a0d6f76ab4b8108 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/b119c2cc8610cb2f3a0d6f76ab4b8108 to your computer and use it in GitHub Desktop.
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