officefileapi-devexpress-dot-spreadsheet-dot-writeprotectionoptions-dot-checkpassword-x28-system-dot-string-x29.md
Checks whether the specified password is the same as the password used to write-protect a workbook.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
bool CheckPassword(
string password
)
Function CheckPassword(
password As String
) As Boolean
| Name | Type | Description |
|---|---|---|
| password | String |
The password to check.
|
| Type | Description |
|---|---|
| Boolean |
true if the password is valid; otherwise, false.
|
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();
}
}
Using workbook As New Workbook()
workbook.LoadDocument("WriteProtectedDocument.xlsx")
RemoveWriteProtection(workbook, "password")
End Using
' ...
Private Sub RemoveWriteProtection(workbook As Workbook, password As String)
Dim wpOptions As WriteProtectionOptions = workbook.DocumentSettings.WriteProtection
If wpOptions.IsPasswordProtected AndAlso wpOptions.CheckPassword(password) Then
wpOptions.ClearPassword()
Else
Console.WriteLine("The file is not write-protected or the specified password is invalid!")
Console.ReadKey()
End If
End Sub
See Also
WriteProtectionOptions Interface