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.EncryptedFilePasswordRequested Event

Raises when the RichEditDocumentImportOptions.EncryptionPassword property is not set or returns an invalid password.

Namespace: DevExpress.XtraRichEdit

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

Declaration

public event EncryptedFilePasswordRequestedEventHandler EncryptedFilePasswordRequested
Public Event EncryptedFilePasswordRequested As EncryptedFilePasswordRequestedEventHandler
public event EncryptedFilePasswordRequestedEventHandler EncryptedFilePasswordRequested
Public Event EncryptedFilePasswordRequested As EncryptedFilePasswordRequestedEventHandler

Event Data

The EncryptedFilePasswordRequested event handler receives an argument of the EncryptedFilePasswordRequestedEventArgs type. 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 empty or invalid, the RichEditDocumentServer.EncryptedFilePasswordCheckFailed event raises.

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 or exceeds the number of attempts to enter the password, 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