Sfoglia il codice sorgente
AddProtection() now calls RemoveProtection() as its first task. Otherwise a document could contain many protection elements and this is unallowed.
Below is a code example which uses the new Protection familiy of functions.
// Load a document.
using (DocX document = DocX.Load(@"Test.docx"))
{
if (document.isProtected)
{
Console.WriteLine("Document is protected.");
Console.WriteLine("\tProtection type is " + document.GetProtectionType().ToString());
document.RemoveProtection();
Console.WriteLine("\tProtected removed.");
// Save the document.
document.Save();
Console.WriteLine("\tDocument saved as Test.docx");
}
else
{
Console.WriteLine("Document is not protected.");
document.AddProtection(EditRestrictions.readOnly);
Console.WriteLine("\tProtected added.");
Console.WriteLine("\tProtection type is " + document.GetProtectionType().ToString());
// Save the document.
document.Save();
Console.WriteLine("\tDocument saved as Test.docx");
}
}
// Wait until a user presses a key before exiting.
Console.ReadKey();
master