.NET Word Security-Modify Word Password in C# and Visual Basic

Generally speaking, we must open an encrypted Word document with a correct password and then do other tasks on this document. However, there are lots of password crackers so that the simple password cannot protect document any more. Therefore, it is better to modify password during a certain period. And now, I will introduce a solution to change Word password in C# and Visual Basic.

Because I will use a .NET Word component, Spire.Doc for .NET in this solution, so its dll file has been added as reference in my project at the beginning. Then, modify password step by step.

Initialize a Document(String fileName, String password) constructor instance from specified document. Because the original document is encrypted so the parameter string password is necessary to open document.

Invoke Encrypt(String password) method of Document class to set a new password to  replace the original one.  

Invoke SaveToFile(String fileName) to save this document and then launch it. After debugging, you can find that the original password cannot open document but the new can.

C#

using Spire.Doc;

namespace EncryptionSettings

{

    class Program

    {

        static void Main(string[] args)

        {

            //Load Encrypted Word

            Document doc = new Document(@”E:\Work\Documents\WordDocuments\Card.docx”, “123456”);

            //Modify Password

            doc.Encrypt(“abcxyz”);

            //Save and Launch

            doc.SaveToFile(“EncryptionSettings.docx”);

            System.Diagnostics.Process.Start(“EncryptionSettings.docx”);

        }

    }

}

Visual Basic

Imports Spire.Doc

Namespace EncryptionSettings

    Friend Class Program

        Shared Sub Main(ByVal args() As String)

            ‘Load Encrypted Word

            Dim doc As New Document(“E:\Work\Documents\WordDocuments\Card.docx”, “123456”)

            ‘Modify Password

            doc.Encrypt(“abcxyz”)

            ‘Save and Launch

            doc.SaveToFile(“EncryptionSettings.docx”)

            System.Diagnostics.Process.Start(“EncryptionSettings.docx”)

        End Sub

    End Class

End Namespace

What’s more, if you don’t want to encrypt document any more, invoke RemoveEncryption() method of Document class to open document without password.

Download Spire.Doc for .NET Here

P.S. The .NET Office component, Spire.Office for .NET can be used to realize this function as well.

.NET Word Page Layout-Set Word Column Display in C# and Visual Basic

Page Column Display is one kind of page layout setting. It separates page contents into two or three columns and users can set the column width and space between columns to have the satisfied layout. In this article, I will introduce an easy method to change the original Word layout as Word column layout in C# and Visual Basic.

In this example, I just separate contents of one document into two columns. At the beginning, I should prepare some materials: Word document and the .NET Word component, Spire.Doc for .NET to realize function to set Word column. Then, add the component dll as reference in my project.

Now, follow the steps. Firstly, initialize a Document instance and invoke Document.LoadFromFile method with overload string file name to load the prepared Word document. Secondly, initialize a new instance of Column class from the existing document. Invoke ColumnCollection.Add method to add columns for section of document. The overload passed to this method is this Column instance. If you want to set column width and space between current and next column, you need to set Width and Space property of Column class before invoking ColumnCollection.Add method. Thirdly, invoke Document.SaveToFile method with string filename and FileFormat overloads to save changed document and launch for viewing.

C#

using Spire.Doc;

namespace WordColumns

{

    class Program

    {

        static void Main(string[] args)

        {

            //Load Document

            Document document = new Document();

            document.LoadFromFile(@”E:\Work\Documents\WordDocuments\Blues Introduction.docx”);

 

            //Add Columns

            Column col = new Column(document);

            document.Sections[0].Columns.Add(col);

 

            //Save and Launch

            document.SaveToFile(“WordColumns.docx”, FileFormat.Docx);

            System.Diagnostics.Process.Start(“WordColumns.docx”);

        }

    }

}

Visual Basic

Imports Spire.Doc

Namespace WordColumns

    Friend Class Program

        Shared Sub Main(ByVal args() As String)

            ‘Load Document

            Dim document As New Document()

            document.LoadFromFile(“E:\Work\Documents\WordDocuments\Blues Introduction.docx”)

 

            ‘Add Columns

            Dim col As New Column(document)

            document.Sections(0).Columns.Add(col)

 

            ‘Save and Launch

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

            System.Diagnostics.Process.Start(“WordColumns.docx”)

        End Sub

    End Class

End Namespace

After debugging, we can get the following result:

Download Spire.Doc for .NET Here

P.S. The .NET Office component, Spire.Office for .NET can be used to realize this function as well.