Security
Содержание
[
Скрывать
]BuiltInDocumentProperties.Security property
Указывает уровень безопасности документа в виде числового значения.
public DocumentSecurity Security { get; set; }
Примечания
Используйте это свойство только в информационных целях, поскольку Microsoft Word не всегда устанавливает это свойство. Это свойство доступно только в документах DOC и OOXML.
Чтобы защитить или снять защиту документа, используйте the Protect
иUnprotect
методы.
Aspose.Words обновляет это свойство до правильного значения перед сохранением документа.
Примеры
Показывает, как использовать свойства документа для отображения уровня безопасности документа.
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);
Смотрите также
- enum DocumentSecurity
- class BuiltInDocumentProperties
- пространство имен Aspose.Words.Properties
- сборка Aspose.Words