How to Encrypt Word Document – C#/VB.NET

Encrypt Word is the most frequently used method to protect document.

Actually, there are several important and secret documents in our daily life, such as technology materials of one company, papers and so on. In order to protect these documents, owners will encrypt them with passwords. Just having the correct passwords, people can open encrypted documents.

Besides encryption with passwords, owner can set permissions for document. For example, I can allow that one document can be edited or printed.

In this post, I will introduce a simple method to encrypt Word document with C#/VB.NET.

Note:Spire.Doc dll file has been added as reference in project.

Detailed Steps Shown as Following:

  1. Load document which I want to encrypt from computer.
  2. Encrypt document by using document.Encrypt() method. There is a parameter passed to method, string password.
  3. Save and launch file.

Main Coding:


using System;
using Spire.Doc;
using Spire.Doc.Documents;

namespace Encrypt_Word
    class Encryption
        static void Main(string[] args)

            //Load Document
            Document document = new Document();
            document.LoadFromFile(@”D:\work\My Documents\Essays.docx”);


            //Save and Launch
            document.SaveToFile(“Encryption.docx”, FileFormat.Docx);


Imports System
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace Encrypt_Word
    Friend Class Encryption
        Shared Sub Main(ByVal args() As String)

            ‘Load Document
            Dim document As New Document()
            document.LoadFromFile(“D:\work\My Documents\Essays.docx”)

            ‘Save and Launch

            document.SaveToFile(“Encryption.docx”, FileFormat.Docx)

        End Sub
    End Class
End Namespace

Permission Settings:




With permission, we can find that some tools in toolbar are invalid.

Result Shown as Following:

With Password

With Permission


Click Here to Learn more about Spire.Doc

Click Here to Download Spire.Doc


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s