Просмотр исходного кода

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
coffeycathal_cp 15 лет назад
Родитель
Сommit
28ad9c32b2
1 измененных файлов: 3 добавлений и 0 удалений
  1. 3
    0
      DocX/DocX.cs

+ 3
- 0
DocX/DocX.cs Просмотреть файл

public void AddProtection(EditRestrictions er) public void AddProtection(EditRestrictions er)
{ {
// Call remove protection before adding a new protection element.
RemoveProtection();
if (er == EditRestrictions.none) if (er == EditRestrictions.none)
return; return;

Загрузка…
Отмена
Сохранить