Search code examples
ms-wordopenxmlopenxml-sdk

Is there a way in (DocumentFormat.OpenXml.Wordprocessing) to write protect a paragraph?


I understand you can protect the whole document with something like this: myDocument.ExtendedFilePropertiesPart.Properties.DocumentSecurity= new DocumentSecurity("4");

Is there a way to do the same, but to just a single paragraph ?

-thanks in advance


Solution

  • Yes, although I'm on a mobile device and can't check the exact syntax at the moment. But you can find it, yourself.

    Start a new document, fairly simple content. In the Word application go to the Developer tab. There's a group/button "Restrict Editing" / "Protect document" (depending on the version of Word). That displays a task pane where you can define the kind of restriction. Select everything BUT the paragraph, then from Step 2 choose "Read-only" (or something like that - not protect for comments or form fields). Make the selection editable for "everyone". In the next step, activate the protection.

    Once you have this working, open the document in the Open XML SDK Productivity Tool and you can inspect the underlying Word Open XML syntax. Plus, if you're using the SDK (that's not clear from your question) it will also show you the code for generating the document.