Skip to main content
Row

WriteProtectionOptions.CheckPassword(String) Method

Checks whether the specified password is the same as the password used to write-protect a workbook.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v24.1.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

bool CheckPassword(
    string password
)

Parameters

Name Type Description
password String

The password to check.

Returns

Type Description
Boolean

true if the password is valid; otherwise, false.

Remarks

The following example checks a given password and removes write-protection from a workbook if the password is valid:

using (Workbook workbook = new Workbook())
{
    workbook.LoadDocument("WriteProtectedDocument.xlsx");
    RemoveWriteProtection(workbook, "password");
}
// ...

private void RemoveWriteProtection(Workbook workbook, string password)
{
    var wpOptions = workbook.DocumentSettings.WriteProtection;
    if (wpOptions.IsPasswordProtected && wpOptions.CheckPassword(password))
        wpOptions.ClearPassword();
    else
    {
        Console.WriteLine("The file is not write-protected or the specified password is invalid!");
        Console.ReadKey();
    }
}
See Also