Protect or Unprotect Word Documents using C++

Protect Unprotect Word C++

The protection of digital documents has always been a hot topic. As far as Word documents are concerned, MS Word provides several content protection features that limit the user’s access to the document. You can protect the document with a password and apply desired restrictions to avoid unauthorized access. In accordance with that, this article covers how to automate Word document protection within C++ applications. Particularly, you will learn how to protect and unprotect Word documents using C++.

C++ API to Protect/Unprotect Word Documents

Aspose.Words for C++ is built for creating and manipulating MS Word documents within C++ applications. The API provides basic as well as advanced document manipulation features that also cover protecting and unprotecting Word documents. You can either download the API package or install it from NuGet.

PM> Install-Package Aspose.Words.Cpp

Protect a Word Document using C++

Aspose.Words for C++ allows you to use the following protection types in order to limit the user’s access to the document.

  • AllowOnlyComments – Modification of comments in the document is allowed.
  • AllowOnlyFormFields – The user can only enter data in the form fields in the document.
  • AllowOnlyRevisions – The user can only add revision marks to the document.
  • ReadOnly – No changes are allowed to the document (available since Microsoft Word 2003).
  • NoProtection – The document is not protected.

The following are the steps to protect a Word document.

The following code sample shows how to protect a Word document using C++.

Unprotect Word Document using C++

Aspose.Words for C++ lets you unprotect MS Word documents even if you do not know the password. In order to unprotect a password-protected Word document, you can follow the below steps.

Get a Free License

You can get a free temporary license in order to try the API without evaluation limitations.

Conclusion

MS Word document protection has been widely in practice in order to protect the documents from unauthorized users. Keeping an eye on it, this article covered how to protect Word documents as well as unprotect the password-protected documents using C++. You can explore more about the C++ Word API using documentation.

See Also