Last active
February 27, 2020 02:43
-
-
Save aspose-com-gists/b119c2cc8610cb2f3a0d6f76ab4b8108 to your computer and use it in GitHub Desktop.
Protect/Unprotect Word Document in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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