Skip to main content

RichEditControl.EncryptedFilePasswordRequested Event

Occurs when the RichEditDocumentImportOptions.EncryptionPassword property is not set.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.XtraRichEdit.v24.1.dll

NuGet Packages: DevExpress.Win.PivotGrid, DevExpress.Win.RichEdit, DevExpress.Win.TreeMap

Declaration

public event EncryptedFilePasswordRequestedEventHandler EncryptedFilePasswordRequested

Event Data

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

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
DocumentName Gets the name of the encrypted document.
Password Gets or sets the password used to encrypt the document.

Remarks

The EncryptedFilePasswordRequested event allows you to specify a password in code using the Password property. If the given password is invalid, the RichEditDocumentServer.EncryptedFilePasswordCheckFailed event raises.

View Example: Document Encryption (Simple Example)

private void RichEditControl1_EncryptedFilePasswordRequested(object sender, EncryptedFilePasswordRequestedEventArgs e)
{
    //Count the number of attempts to enter the password
    if (tryCount > 0)
    {
        tryCount--;
    }
}

private void RichEditControl1_EncryptedFilePasswordCheckFailed(object sender, EncryptedFilePasswordCheckFailedEventArgs e)
{

    //Analyze the error that led to this event
    //Depending on the user input and number of attempts,
    //Prompt user to enter a password again
    //or create an empty file
    switch (e.Error)
    {
        case RichEditDecryptionError.PasswordRequired:
            if (tryCount > 0)
            {
                e.TryAgain = true;
                e.Handled = true;
                MessageBox.Show("You did not enter the password!", String.Format(" {0} attempts left", tryCount));
            }
            else
                e.TryAgain = false;

            break;

        case RichEditDecryptionError.WrongPassword:
            if (tryCount > 0)
            {
                if ((MessageBox.Show("The password is incorrect. Try Again?", String.Format(" {0} attempts left", tryCount),
                    MessageBoxButtons.YesNo)) == DialogResult.Yes)
                {
                    e.TryAgain = true;
                    e.Handled = true;
                }

            }
            break;
    }
}
See Also