The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
All docs
V19.1
19.2 (EAP/Beta)
19.1
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

RichEditDocumentServer.EncryptedFilePasswordCheckFailed Event

Occurs when the encryption password is empty or invalid.

Namespace: DevExpress.XtraRichEdit

Assembly: DevExpress.RichEdit.v19.1.Core.dll

Declaration

public event EncryptedFilePasswordCheckFailedEventHandler EncryptedFilePasswordCheckFailed
Public Event EncryptedFilePasswordCheckFailed As EncryptedFilePasswordCheckFailedEventHandler
public event EncryptedFilePasswordCheckFailedEventHandler EncryptedFilePasswordCheckFailed
Public Event EncryptedFilePasswordCheckFailed As EncryptedFilePasswordCheckFailedEventHandler

Event Data

The EncryptedFilePasswordCheckFailed event handler receives an argument of the EncryptedFilePasswordCheckFailedEventArgs type. The following properties provide information specific to this event.

Property Description
DocumentName Gets the encrypted document's name.
Error Obtains the error type caused the event to raise.
Handled Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing.
(Inherited from HandledEventArgs)
TryAgain Gets or sets whether to prompt with a password again.

Remarks

Hanlde the EncryptedFilePasswordCheckFailed event to determine the password error (RichEditDecryptionError.PasswordRequired or RichEditDecryptionError.WrongPassword, and specify whether to enable a new password request (TryAgain).

If the TryAgain property is set to true, the RichEditDocumentServer.EncryptedFilePasswordRequested event occurs. The RichEditDocumentServer.InvalidFormatException event fires when the TryAgain property is not specifies or set to false.

The code sample below shows how to handle the RichEditDocumentServer.EncryptedFilePasswordRequested and RichEditDocumentServer.EncryptedFilePasswordCheckFailed events to prompt users to enter a password. If the user cancels the operation, the RichEditDocumentServer loads an empty file.

Note

A complete code sample project is available at https://github.com/DevExpress-Examples/how-to-open-and-save-encrypted-files.


private static void Server_EncryptedFilePasswordRequested(object sender, EncryptedFilePasswordRequestedEventArgs e)
{
    //Prompt the user to enter the password
    Console.WriteLine("Enter password:");
    e.Password = Console.ReadLine();
    e.Handled = true;
}

private static void Server_EncryptedFilePasswordCheckFailed(object sender, EncryptedFilePasswordCheckFailedEventArgs e)
{
    //Analyze the password error:
    switch (e.Error)
    {
        //If the password is empty, raise the request again
        case RichEditDecryptionError.PasswordRequired:
            Console.WriteLine("You did not enter the password!");
            e.TryAgain = true;
            e.Handled = true;
        break;
        //If the password is invalid, ask user whether to continue the operation:
        case RichEditDecryptionError.WrongPassword:
            Console.WriteLine("The password is incorrect. Try Again? (yes/no)");
            string answer = Console.ReadLine()?.ToLower();
            if (answer == "y")
            {
                e.TryAgain = true;
                e.Handled = true;
            }
            //If user cancels the operation, open an empty file:
            else
            {
                Console.WriteLine("Password check failed. Loading an empty file...");
            }
        break;
    }
}

private static void Server_InvalidFormatException(object sender, RichEditInvalidFormatExceptionEventArgs e)
{
    RichEditDocumentServer server = (RichEditDocumentServer)sender;

    //Save and open the resulting file
    server.SaveDocument("EmptyFile.docx", DocumentFormat.OpenXml);
    Process.Start("EmptyFile.docx");
}

See Also