• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

Class WriteProtection

Provides access to write-protection settings for a document. Write protection recommends that the document be opened as read-only. An optional password can be set that is required to disable the write protection. Maps to <w:writeProtection> in settings.xml.

Inheritance
object
WriteProtection
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: DRIT.Document
Assembly: DRIT.Document.dll
Syntax
public class WriteProtection

Properties

AlgorithmName

Gets the hash algorithm name (e.g. "SHA-512"), or null.

Declaration
public string AlgorithmName { get; }
Property Value
Type Description
string

HasPassword

Gets a value indicating whether a password has been set.

Declaration
public bool HasPassword { get; }
Property Value
Type Description
bool

HashValue

Gets the password hash (base64), or null if no password is set.

Declaration
public string HashValue { get; }
Property Value
Type Description
string

Recommended

Gets or sets a value indicating whether the document is recommended to be opened as read-only. Maps to <w:writeProtection w:recommended="true"/>.

Declaration
public bool Recommended { get; set; }
Property Value
Type Description
bool

SaltValue

Gets the salt value (base64), or null if no salt is used.

Declaration
public string SaltValue { get; }
Property Value
Type Description
string

SpinCount

Gets the spin count for the hash, or 0 if not set.

Declaration
public int SpinCount { get; }
Property Value
Type Description
int

Methods

CanUnprotect(string)

Determines whether the specified password can remove the current write protection. Documents without a password return true.

Declaration
public bool CanUnprotect(string password)
Parameters
Type Name Description
string password

The password to validate.

Returns
Type Description
bool

true if the password matches or no password is configured.

ClearPassword()

Clears the password, removing the hash, salt, and algorithm settings.

Declaration
public void ClearPassword()

SetPassword(string)

Sets the write-protection password, computing the OOXML password hash. Also sets Recommended to true.

Declaration
public void SetPassword(string password)
Parameters
Type Name Description
string password

The password to set.

StartEnforcingWriteProtection(string)

Starts the read-only recommendation, optionally protecting its removal with a password.

Declaration
public void StartEnforcingWriteProtection(string password = null)
Parameters
Type Name Description
string password

The password to set, or null for a recommendation without a password.

StopEnforcingWriteProtection()

Removes the read-only recommendation and all write-protection password metadata.

Declaration
public void StopEnforcingWriteProtection()

StopEnforcingWriteProtection(string)

Removes the read-only recommendation after validating the password, when one is configured.

Declaration
public void StopEnforcingWriteProtection(string password)
Parameters
Type Name Description
string password

The password used when write protection was enabled.

Exceptions
Type Condition
UnauthorizedAccessException

The password is incorrect.

Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX