Open a Document Read-Only

Sometimes, you may have a document that needs a review, but you do not want reviewers to randomly modify your content. Aspose.Words allows you to make the permission of your document read-only so that the content can be copied or read, but not modified. This will prevent content from being removed or added to your document.

This article explains how to make a document read-only.

Make a Document Read-Only

Aspose.Words has the public class WriteProtection that specifies write protection settings for a document. You do not create instances of this class directly.

Write protection shows whether the author has recommended opening a document as read-only and/or requiring a password to modify the document.

Aspose.Words allows you to make a document read-only to restrict editing by using the ReadOnlyRecommended property and the SetPassword method.

The ReadOnlyRecommended property is password‑secured, so if you do not set a password before applying the ReadOnlyRecommended property, then other users can simply open the document as if it were unprotected. You access the document protection settings and set a write protection password via the SetPassword method.

If you need to check if a document has a write protection password that restricts it from editing, you can use the IsWriteProtected property.

The following code example shows how to make a document read-only:

Remove Read-Only Restriction

If you do not want a user to open your document as read-only, you can simply set the ReadOnlyRecommened property to false or select ProtectionType as NoProtection.

The following code example shows how to remove read-only access for a document:


FAQ

  1. Q: How do I make a document read‑only with a password?
    A: Load the document, set document.WriteProtection.ReadOnlyRecommended = true; and then call document.WriteProtection.SetPassword("yourPassword");. Finally, save the document. The password protects the read‑only recommendation.

  2. Q: Can I check whether a document is currently write‑protected?
    A: Yes. Use the document.WriteProtection.IsWriteProtected property; it returns true if a write‑protection password has been set.

  3. Q: How can I remove the read‑only recommendation from an existing document?
    A: Set document.WriteProtection.ReadOnlyRecommended = false; or change the protection type to ProtectionType.NoProtection, then save the document.

  4. Q: Is the read‑only password a security feature?
    A: The password is stored as a document property and can be removed by users who can edit the document’s metadata. It deters casual editing but should not be considered strong security.

  5. Q: Are Aspose.Words licenses backward compatible with older library versions?
    A: Yes. An Aspose.Words license file works with earlier versions of the library, provided the license file format has not changed. However, features introduced in newer versions will not be available when using older library releases.