Add Password to Word Document with NET REST API

This article describes how to add password to Word document with NET REST API. You will learn to automatically put a password on a Word document with C# REST API using the .NET cloud SDK. Various options are discussed to protect the Word file with different protection settings.

Prerequisite

Steps to Add Password to Word DOC with C# REST API

  1. Instantiate an object of the WordsApi class to set a password
  2. Read the input Word file into a byte array to protect the document
  3. Create the ProtectionRequestV2 class object and set its parameters
  4. Instantiate the ProtectDocumentOnlineRequest object by providing the required arguments
  5. Call the ProtectDocumentOnline method to add a password
  6. Save the protected Word file

The above steps describe how to add password protection to Word document with C# Low Code API. Commence the process by reading the input Word file into a byte array followed by declaration and initialization of the ProtectionRequestV2 object by passing the password and protection type. Finally, create the ProtectDocumentOnlineRequest object using the above properties and call the ProtectDocumentOnline() method to apply the password.

Code to Add a Password to Word Document with NET REST API

This code demonstrates how to set password on Word document with C# Low Code API. You may select desired protection type from the ProtectionTypeEnum enumerator including AllowOnlyRevisions, AllowOnlyComments, AllowOnlyFormFields, ReadOnly, and NoProtection. The output file is created in the cloud and can be retrieved using the Document property of the response provided by the API.

In this topic, we have explored the processing of protecting a Word file using a password. If you want to compress a Word file, refer to the following article: Compress Word File with NET REST API.

 English