BuiltInDocumentPropertiesSecurity Property

Specifies the security level of a document as a numeric value.

Namespace:  Aspose.Words.Properties
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public DocumentSecurity Security { get; set; }

Property Value

Type: DocumentSecurity
Remarks

Use this property for informational purposes only because Microsoft Word does not always set this property. This property is available in DOC and OOXML documents only.

To protect or unprotect a document use the Protect(ProtectionType, String) and Unprotect methods.

Aspose.Words updates this property to a correct value before saving a document.

Examples
Shows how to use document properties to display the security level of a document.
// Create a blank document, which has no security of any kind by default
Document doc = new Document();

// The "Security" property serves as a description of the security level of a document
Assert.AreEqual(DocumentSecurity.None, doc.BuiltInDocumentProperties.Security);

// Upon saving a document after setting its security level, Aspose automatically updates this property to the appropriate value
doc.WriteProtection.ReadOnlyRecommended = true;
doc.Save(ArtifactsDir + "Properties.Security.ReadOnlyRecommended.docx");

// We can open a document and glance at its security level like this
Assert.AreEqual(DocumentSecurity.ReadOnlyRecommended, 
    new Document(ArtifactsDir + "Properties.Security.ReadOnlyRecommended.docx").BuiltInDocumentProperties.Security);

// Create a new document and set it to Write-Protected
doc = new Document();

Assert.False(doc.WriteProtection.IsWriteProtected);
doc.WriteProtection.SetPassword("MyPassword");
Assert.True(doc.WriteProtection.ValidatePassword("MyPassword"));
Assert.True(doc.WriteProtection.IsWriteProtected);
doc.Save(ArtifactsDir + "Properties.Security.ReadOnlyEnforced.docx");

// This document's security level counts as "ReadOnlyEnforced" 
Assert.AreEqual(DocumentSecurity.ReadOnlyEnforced,
    new Document(ArtifactsDir + "Properties.Security.ReadOnlyEnforced.docx").BuiltInDocumentProperties.Security);

// Since this is still a descriptive property, we can protect a document and pick a suitable value ourselves
doc = new Document();

doc.Protect(ProtectionType.AllowOnlyComments, "MyPassword");
doc.BuiltInDocumentProperties.Security = DocumentSecurity.ReadOnlyExceptAnnotations;
doc.Save(ArtifactsDir + "Properties.Security.ReadOnlyExceptAnnotations.docx");

Assert.AreEqual(DocumentSecurity.ReadOnlyExceptAnnotations,
    new Document(ArtifactsDir + "Properties.Security.ReadOnlyExceptAnnotations.docx").BuiltInDocumentProperties.Security);
See Also