We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback


Trusted by the world’s leading companies

Syncfusion Trusted Companies

Overview

Protect your sensitive information and control document access with ease. The Syncfusion .NET Word Library (DocIO) empowers you to programmatically encrypt and decrypt Word documents in C# and restrict editing privileges, all without relying on Microsoft Word or interop dependencies.


How to encrypt a Word document with a password in C#

  1. Install the NuGet package: Install the Syncfusion.DocIO.Net.Core NuGet package in your project. 
  2. Open Word document: Create a FileStream object to represent the input Word document.
  3. Load in .NET Word Library: Create a WordDocument object by passing the FileStream object.
  4. Encrypt with password: Call the EncryptDocument method of the WordDocument object by passing the password.
  5. Save Word document: Save the WordDocument object to the FileStream object.

Here is an example of how to encrypt a Word document in C# using the Syncfusion .NET Word Library (DocIO).

//Load an existing Word document.
using FileStream inputStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read);
using WordDocument document = new WordDocument(inputStream, FormatType.Docx);

//Encrypt the Word document with a password.
document.EncryptDocument("password");

//Save the Word document.
using FileStream outputStream = new FileStream("Sample.docx", FileMode.Create, FileAccess.Write);
document.Save(outputStream, FormatType.Docx);

How to decrypt a password-protected Word document in C#

  1. Install NuGet package: Install the Syncfusion.DocIO.Net.Core NuGet package in your project. 
  2. Open password-protected Word document: Create a FileStream object to represent the input Word document.
  3. Load in .NET Word Library: Create a WordDocument object by passing the FileStream object and password.
  4. Decrypt Word document: Call the RemoveEncryption method of the WordDocument object.
  5. Save Word document: Save the WordDocument object to the FileStream object.

Here is an example of how to decrypt a password-protected Word document in C# using the Syncfusion .NET Word Library (DocIO).

//Load an existing Word document with password.
using FileStream inputStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read);
using WordDocument document = new WordDocument(inputStream, FormatType.Docx, "password");

//Decrypt the Word document.
document.RemoveEncryption();

//Save the Word document.
using FileStream outputStream = new FileStream("Sample.docx", FileMode.Create, FileAccess.Write);
document.Save(outputStream, FormatType.Docx);

Restrict editing

The .NET Word Library (DocIO) provides comprehensive options for restricting editing within Word documents programmatically in C#.

Allow only reading

In this mode, users can view the document content but cannot make any edits, ensuring document integrity.

Allow only comments

In this mode, users can add or modify comments in the document, but cannot change the actual content.

Allow only form fields

In this mode, form fields remain accessible while the Word document’s main content is protected.

Allow only revisions

In this mode, users can suggest changes but cannot directly edit existing text, enabling transparent review and feedback.



Awards

Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion is proud to hold the following industry awards.

Scroll up icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon