Skip to main content
All docs
V23.2

AsyncDownloadPolicy.Downloading Event

Allows you to spot an initiated download, check connection parameters, and cancel (or allow, if the SuppressAll() policy is active) the operation.

Namespace: DevExpress.Data

Assembly: DevExpress.Data.v23.2.dll

NuGet Package: DevExpress.Data

Declaration

public static event AsyncDownloadPolicy.WeakEventHandler<AsyncDownloadPolicy.DownloadingEventArgs> Downloading

Event Data

The Downloading event's data class is AsyncDownloadPolicy.DownloadingEventArgs. 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.
IsTrustedUri Gets whether the processed resource is in a “safe” resource whitelist. Inherited from AsyncDownloadPolicy.AsyncDownloaderCancelEventArgs.
Method Gets the HTTP method.
ThrowOnNonTrustedUri Gets or sets whether to throw an exception for unwanted download requests. Inherited from AsyncDownloadPolicy.AsyncDownloaderCancelEventArgs.
Uri Gets the processed resource identifier. Inherited from AsyncDownloadPolicy.AsyncDownloaderCancelEventArgs.
ValueType Gets a value that identifies the group of controls to which an individual control (that initiated the download) belongs.

Remarks

static void Main() {
    // ...
    DevExpress.Data.AsyncDownloadPolicy.Downloading += AsyncDownloadPolicy_Downloading;
    Application.Run(new Form1());
}
private static void AsyncDownloadPolicy_Downloading(object sender, DevExpress.Data.AsyncDownloadPolicy.DownloadingEventArgs e) {
    e.Cancel = !e.Uri.AbsoluteUri.StartsWith(@"https://www.devexpress.com");
}

Different DevExpress UI components with the same functionality (for example, separate WinForms PictureEdit controls that load images from URI paths) utilize the same HttpClient. As a result, the event’s e.ValueType parameter is the same for all individual controls (for aforementioned PictureEdit controls, e.ValueType returns ImageOrSvgImageResult). This technique allows you to identify the group of controls to which an individual control (that initiated the download) belongs.

public Form1() {
    InitializeComponent();
    AsyncDownloadPolicy.Downloading += AsyncDownloadPolicy_Downloading;
}
Dictionary<int, string> whitelist = new Dictionary<int, string>() {
    { 0, "www.devexpress.com" },
    { 1, "community.devexpress.com" },
    { 2, "docs.devexpress.com" },
    { 3, "supportcenter.devexpress.com" }
};
private void AsyncDownloadPolicy_Downloading(object sender, AsyncDownloadPolicy.DownloadingEventArgs e) {
    string result = e.ValueType.Name;
    // Checks whether a picture editor initiated the download.
    if(result == "ImageOrSvgImageResult")
        // Cancels downloading from domains that are not in the white list.
        e.Cancel = !whitelist.Values.Contains(e.Uri.Authority);
}
private void loadImageButton_Click(object sender, EventArgs e) {
    pictureEdit1.LoadAsync(/* YOUR_URL */);
}  

Read the following topic for detailed information: Suppress Control Requests to Download Data from External URLs.

See Also