---
title: "Make a Document Read-Only in C#"
---


{{% alert color="grey" %}}

## Purpose Summary

This page explains how to open a document in read-only mode programmatically.

{{% /alert %}}

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.

{{% alert color="primary" %}}

Applying the read-only option to your document does not prevent someone from creating a new copy of it and saving it with another name.

{{% /alert %}}

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

## How to Make a Document Read-Only

Aspose.Words has the public class [WriteProtection](https://reference.aspose.com/words/net/aspose.words.settings/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](https://reference.aspose.com/words/net/aspose.words.settings/writeprotection/readonlyrecommended/) property and the [SetPassword](https://reference.aspose.com/words/net/aspose.words.settings/writeprotection/setpassword/) method.

{{% alert color="primary" %}}

In Microsoft Word, you can create a Read-Only document in a similar way using both:

* “Always Open Read-Only” (File → Info → Protect Document)
* "Password to modify" (Save As → Tools → General Options → Password)

{{% /alert %}}

{{% alert color="primary" %}}

Users can also restrict document editing by selecting [ProtectionType](https://reference.aspose.com/words/net/aspose.words/protectiontype/) as **ReadOnly**, but this is another feature that provides more advanced protection capabilities. There is such a function in Microsoft Word, respectively, it is implemented in Aspose.Words.

**ProtectionType** will be described in detail in one of the following articles – “Restrict Document Editing”.

{{% /alert %}}

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.

{{% alert color="primary" %}}

Note that the password being set is just a property in a document that can be removed if the document properties are accessed. Accordingly, such a password is not a guarantee of the document security.

{{% /alert %}}

If you need to check if a document has a write protection password that restricts it from editing, you can use the [IsWriteProtected](https://reference.aspose.com/words/net/aspose.words.settings/writeprotection/iswriteprotected/) property.

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

{{< gist "aspose-words-gists" "7cf6735e83804ba8942663695b22ee42" "read-only-protection.cs" >}}

## 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:

{{< gist "aspose-words-gists" "7cf6735e83804ba8942663695b22ee42" "remove-read-only-restriction.cs" >}}

## Related APIs

- [WriteProtection](https://reference.aspose.com/words/net/aspose.words.settings/writeprotection/)  
- [WriteProtection.ReadOnlyRecommended](https://reference.aspose.com/words/net/aspose.words.settings/writeprotection/readonlyrecommended/)  
- [WriteProtection.SetPassword](https://reference.aspose.com/words/net/aspose.words.settings/writeprotection/setpassword/)  
- [WriteProtection.IsWriteProtected](https://reference.aspose.com/words/net/aspose.words.settings/writeprotection/iswriteprotected/)  
- [ProtectionType](https://reference.aspose.com/words/net/aspose.words/protectiontype/)

------

## 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.