DocumentSecurity

DocumentSecurity enumeration

Used as a value for the Security property. Specifies the security level of a document as a numeric value.

[Flags]
public enum DocumentSecurity

Values

NameValueDescription
None0There are no security states specified by the property.
PasswordProtected1The document is password protected. (Note has never been seen in a document so far).
ReadOnlyRecommended2The document to be opened read-only if possible, but the setting can be overridden.
ReadOnlyEnforced4The document to always be opened read-only.
ReadOnlyExceptAnnotations8The document to always be opened read-only except for annotations.

Examples

Shows how to use document properties to display the security level of a document.

Document doc = new Document();

Assert.That(doc.BuiltInDocumentProperties.Security, Is.EqualTo(DocumentSecurity.None));

// If we configure a document to be read-only, it will display this status using the "Security" built-in property.
doc.WriteProtection.ReadOnlyRecommended = true;
doc.Save(ArtifactsDir + "DocumentProperties.Security.ReadOnlyRecommended.docx");

Assert.That(new Document(ArtifactsDir + "DocumentProperties.Security.ReadOnlyRecommended.docx").BuiltInDocumentProperties.Security, Is.EqualTo(DocumentSecurity.ReadOnlyRecommended));

// Write-protect a document, and then verify its security level.
doc = new Document();

Assert.That(doc.WriteProtection.IsWriteProtected, Is.False);

doc.WriteProtection.SetPassword("MyPassword");

Assert.That(doc.WriteProtection.ValidatePassword("MyPassword"), Is.True);
Assert.That(doc.WriteProtection.IsWriteProtected, Is.True);

doc.Save(ArtifactsDir + "DocumentProperties.Security.ReadOnlyEnforced.docx");

Assert.That(new Document(ArtifactsDir + "DocumentProperties.Security.ReadOnlyEnforced.docx").BuiltInDocumentProperties.Security, Is.EqualTo(DocumentSecurity.ReadOnlyEnforced));

// "Security" is a descriptive property. We can edit its value manually.
doc = new Document();

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

Assert.That(new Document(ArtifactsDir + "DocumentProperties.Security.ReadOnlyExceptAnnotations.docx").BuiltInDocumentProperties.Security, Is.EqualTo(DocumentSecurity.ReadOnlyExceptAnnotations));

See Also