Articles in this section
Category / Section

How to make a Word document as Read-only document in C# and VB.NET?

4 mins read

Syncfusion® Essential® DocIO is a .NET Word library used to create, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can restrict a Word document from editing either by providing a password or without password.

The following are types of Microsoft Word document protection:

  1. AllowOnlyComments: You can add or modify only the comments in the Word document.
  2. AllowOnlyFormFields: You can modify the form field values in the Word document.
  3. AllowOnlyRevisions: Allow only revisions to be made to existing content. After enabling this flag, accept and reject changes options in Microsoft Word application are disabled.
  4. AllowOnlyReading: You can only view the content in the Word document.
  5. NoProtection: You can access or edit the Word document contents as normally.

From this page, you can learn how to make a Word document as Read-only document (prevent from editing) Syncfusion® Word library (Essential® DocIO) in C# and VB.NET.

Steps to make a Word document as Read-only document in C#

  1. Create a new C# console application project.

Create new C# console app in WinForms

  1. Install Syncfusion.DocIO.WinForms NuGet package as a reference to your .NET Framework applications from the NuGet.org.

Install WinForms NuGet packages

  1. Include the following namespace in the Program.cs file.

C#

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

VB

Imports Syncfusion.DocIO
Imports Syncfusion.DocIO.DLS
  1. Use the following code to make a Word document as Read-only document.

C#

//Opens a Word document
WordDocument document = new WordDocument(@"Template.docx");
//Sets the protection with password and it allows only to view the content in the Word document.
document.Protect(ProtectionType.AllowOnlyReading, "password");
//Saves the Word document
document.Save("Protection.docx", FormatType.Docx);
document.Close();

VB

'Opens a Word document 
Dim document As New WordDocument("Template.docx")
'Sets the protection with password and it allows only to view the content in the Word document.
document.Protect(ProtectionType.AllowOnlyReading, "password")
'Saves the Word document
document.Save("Protection.docx", FormatType.Docx)
document.Close()

A complete working example of making a Word document as Read-only document in C# can be downloaded from here.

By executing the program, you will get the output Word document as follows:

Output Word document

Take a moment to peruse the documentation, where you can find basic Word document processing options along with features like mail merge, merge and split documents, find and replace text in the Word document, protect the Word documents, and most importantly PDF and Image conversions with code examples.

Explore more about the rich set of Syncfusion® Word Framework features.

An online example to protect the Word document from editing using DocIO..

See Also:

Protecting Word document from editing

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion® license key in your application to use the components without trail message.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied