Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
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.v20.2.Core.dll

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