SetPassword

WriteProtection.SetPassword method

Belge için yazma koruması parolasını ayarlar.

public void SetPassword(string password)
ParametreTipTanım
passwordStringAyarlanacak şifre. Olamazhükümsüz, ancak boş bir dize de olabilir.

Notlar

Eğer bir şifre belirlenirse, Microsoft Word kullanıcının şifreyi girmesini veya belgeyi salt okunur olarak açmasını isteyecektir.

Örnekler

Bir belgenin parola ile nasıl korunacağını gösterir.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world! This document is protected.");
// En fazla 15 karakter uzunluğunda bir parola girin ve ardından belgenin koruma durumunu doğrulayın.
doc.WriteProtection.SetPassword("MyPassword");
doc.WriteProtection.ReadOnlyRecommended = true;

Assert.IsTrue(doc.WriteProtection.IsWriteProtected);
Assert.IsTrue(doc.WriteProtection.ValidatePassword("MyPassword"));

// Koruma, belgenin programlı olarak düzenlenmesini engellemez veya içeriğini şifrelemez.
doc.Save(ArtifactsDir + "Document.WriteProtection.docx");
doc = new Document(ArtifactsDir + "Document.WriteProtection.docx");

Assert.IsTrue(doc.WriteProtection.IsWriteProtected);

builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
builder.Writeln("Writing text in a protected document.");

Assert.AreEqual("Hello world! This document is protected." +
                "\rWriting text in a protected document.", doc.GetText().Trim());

Ayrıca bakınız