DocumentSecurity

DocumentSecurity enumeration

Используется как значение дляSecurity свойство. Указывает уровень безопасности документа в виде числового значения.

[Flags]
public enum DocumentSecurity

Ценности

ИмяЦенностьОписание
None0Свойство не определяет состояния безопасности.
PasswordProtected1Документ защищен паролем. (Примечание еще ни разу не встречалось в документе).
ReadOnlyRecommended2Документ должен быть открыт только для чтения, если это возможно, но эту настройку можно переопределить.
ReadOnlyEnforced4Документ, который всегда будет открываться только для чтения.
ReadOnlyExceptAnnotations8Документ всегда будет открываться только для чтения, за исключением аннотаций.

Примеры

Показывает, как использовать свойства документа для отображения уровня безопасности документа.

Document doc = new Document();

Assert.AreEqual(DocumentSecurity.None, doc.BuiltInDocumentProperties.Security);

// Если мы настроим документ как доступный только для чтения, он отобразит этот статус с помощью встроенного свойства «Безопасность».
doc.WriteProtection.ReadOnlyRecommended = true;
doc.Save(ArtifactsDir + "DocumentProperties.Security.ReadOnlyRecommended.docx");

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

// Защитите документ от записи, а затем проверьте его уровень безопасности.
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 + "DocumentProperties.Security.ReadOnlyEnforced.docx");

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

// "Безопасность" — описательное свойство. Мы можем редактировать его значение вручную.
doc = new Document();

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

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

Смотрите также