Udostępnij za pośrednictwem


Document Protector Sample

Note

This sample runs only in Microsoft Office Word 2007.

This sample demonstrates how to protect a Word document and the document structure. The sample tool protects the entire document and then enables you to unprotect any or all bookmarks, form fields, and XML nodes that are in the document. You also have the option to password-protect the document.

Security noteSecurity Note:

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To run the sample

  1. Press F5.

  2. On the File menu, click Open, and then browse to the document you want to protect.

  3. Select the items that you do not want to be protected.

  4. Optionally, you can assign a password to the document by clicking Password on the Protection menu.

  5. On the Protection menu, click Protect to apply the protection to the document.

  6. On the File menu, click Save to save your work.

  7. On the File menu, click Exit to exit the Document Protector sample tool.

Requirements

A document that has Bookmark controls, form fields, or XMLNode controls.

Demonstrates

The Document Protector sample tool protects the document and then enables you to select the types of items (XML nodes, form fields, or bookmarks) you want to make available for editing.

See Also

Concepts

Bookmark Control

XMLNode Control

Document Protection in Document-Level Solutions

Password Protection on Office Documents

Walkthroughs Using Word

Other Resources

Document-Level Samples