Back to Devexpress

SpreadsheetControl.EncryptedFilePasswordRequest Event

windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-3085d513.md

latest5.2 KB
Original Source

SpreadsheetControl.EncryptedFilePasswordRequest Event

Occurs when the WorkbookImportOptions.Password property is not set or contains the wrong password.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

csharp
public event EncryptedFilePasswordRequestEventHandler EncryptedFilePasswordRequest
vb
Public Event EncryptedFilePasswordRequest As EncryptedFilePasswordRequestEventHandler

Event Data

The EncryptedFilePasswordRequest event's data class is EncryptedFilePasswordRequestEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
DocumentNameGets the name of the encrypted document.
PasswordGets or sets the password used to encrypt the document.

Remarks

Handle the EncryptedFilePasswordRequest event to prompt a user for a password. You can also use the e.Password property to specify the password in code.

The Password Dialog appears if the e.Handled property is set to false.

Example

The code snippet handles the SpreadsheetControl.EncryptedFilePasswordRequest event to specify a password for loading a password encrypted file.

View Example

csharp
private void SpreadsheetControl1_EncryptedFilePasswordRequest(object sender, EncryptedFilePasswordRequestEventArgs e) {
    if (e.DocumentName == "encrypted_test.xlsx") e.Password = "test";
    if (e.DocumentName == "corrupted.xlsx") e.Password = "000";
    e.Handled = true;
}
vb
Private Sub SpreadsheetControl1_EncryptedFilePasswordRequest(ByVal sender As Object, ByVal e As EncryptedFilePasswordRequestEventArgs)
    If e.DocumentName = "encrypted_test.xlsx" Then
        e.Password = "test"
    End If
    If e.DocumentName = "corrupted.xlsx" Then
        e.Password = "000"
    End If
    e.Handled = True
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the EncryptedFilePasswordRequest event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheet-load-and-save-a-password-encrypted-files/CS/EncryptionExample/Form1.cs#L24

csharp
// The EncryptedFilePasswordRequest event allows you to specify a password in the event handler.
    spreadsheetControl1.EncryptedFilePasswordRequest += SpreadsheetControl1_EncryptedFilePasswordRequest;
}

winforms-spreadsheet-load-and-save-a-password-encrypted-files/VB/EncryptionExample/Form1.vb#L22

vb
' The EncryptedFilePasswordRequest event allows you to specify a password in the event handler.
    AddHandler spreadsheetControl1.EncryptedFilePasswordRequest, AddressOf SpreadsheetControl1_EncryptedFilePasswordRequest
End Sub

See Also

Protection in Spreadsheet Documents

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.XtraSpreadsheet Namespace