DocumentBase::Protect Method (WdProtectionType, Object^%, Object^%, Object^%, Object^%)

 

Applies one of several types of protection to the document.

Namespace:   Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

public:
void Protect(
	WdProtectionType type,
	Object^% noReset,
	Object^% password,
	Object^% useIRM,
	Object^% enforceStyleLock
)

Parameters

type
Type: Microsoft.Office.Interop.Word::WdProtectionType

The protection type for the specified document. WdProtectionType.

noReset
Type: System::Object^%

false to reset form fields to their default values. true to retain the current form field values if the document is protected. If Type is not wdAllowOnlyFormFields, the NoReset argument is ignored.

password
Type: System::Object^%

The password required to remove protection from the document. (See Remarks below.)

useIRM
Type: System::Object^%

Specifies whether to use Information Rights Management (IRM) when protecting the document from changes.

enforceStyleLock
Type: System::Object^%

Specifies whether formatting restrictions are enforced in a protected document.

When a document is protected, users can make only limited changes, such as adding annotations, making revisions, or completing a form. If the document is already protected when you use this method, an exception is thrown.

Avoid using hard-coded passwords in your applications. If a password is required in a procedure, request the password from the user, store it in a variable, and then use the variable in your code.

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example uses the Protect method to allow users to add only comments to the document. To use this example, run it from the ThisDocument class in a document-level project.

No code example is currently available or this language may not be supported.
Return to top
Show: