A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/onizet/html2openxml/wiki/Prevent-Document-Edition below:

Prevent Document Edition · onizet/html2openxml Wiki · GitHub

Sometimes, you just want to generate a static report from Word but do not want to allow the readers to modify the document. With OpenXml, it's quite easy.

This code is mainly to prevent from end-user, but this is only a simple lock and can be disabled easily.

/// <summary>
/// Locks the document to prevent the users writing any accidental modifications.
/// </summary>
public static void PreventDocumentEdition(WordprocessingDocument document)
{
      document.ExtendedFilePropertiesPart.Properties.DocumentSecurity.Text = "8";
      document.ExtendedFilePropertiesPart.Properties.Save();

      Settings settings = document.MainDocumentPart.DocumentSettingsPart.Settings;
      settings.Append(
           new DocumentProtection() {
               Edit = DocumentProtectionValues.ReadOnly,
               Enforcement = new OnOffValue(true)
      });

      settings.Save();
}

You have the option to also allow only Track Changes.. Look at the MSDN about DocumentProtectionValues.

![](Prevent Document Edition_protected.png) Example as Word prevent edition

You can enforce the rule edition with a strong password. Take a look at this sample.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4