DocumentSecurity

DocumentSecurity enumeration

Används som ett värde förSecurity property. Anger säkerhetsnivån för ett dokument som ett numeriskt värde.

[Flags]
public enum DocumentSecurity

Värderingar

namnVärdeBeskrivning
None0Inga säkerhetstillstånd har angetts av egenskapen.
PasswordProtected1Dokumentet är lösenordsskyddat. (Anteckningen har aldrig setts i ett dokument hittills).
ReadOnlyRecommended2Dokumentet ska öppnas skrivskyddat om möjligt, men inställningen kan åsidosättas.
ReadOnlyEnforced4Dokumentet som alltid ska öppnas skrivskyddat.
ReadOnlyExceptAnnotations8Dokumentet ska alltid öppnas skrivskyddat förutom för anteckningar.

Exempel

Visar hur man använder dokumentegenskaper för att visa ett dokuments säkerhetsnivå.

Document doc = new Document();

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

// Om vi konfigurerar ett dokument som skrivskyddat, kommer det att visa denna status med hjälp av den inbyggda egenskapen "Säkerhet".
doc.WriteProtection.ReadOnlyRecommended = true;
doc.Save(ArtifactsDir + "DocumentProperties.Security.ReadOnlyRecommended.docx");

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

// Skrivskydda ett dokument och verifiera sedan dess säkerhetsnivå.
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);

// "Säkerhet" är en beskrivande egenskap. Vi kan redigera dess värde manuellt.
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);

Se även