6.23File transfer event handler

Created on Aug 17, 2026~3 min read

The IHttpFileTransferEventHandler interface allows you to define pre-processing operations for downloading or uploading files. By implementing this interface, you can create a custom file transfer event handler, such as the CustomFileTransferEventHandler class:

cs
public class CustomFileTransferEventHandler : IHttpFileTransferEventHandler{    // Action when the file transfer starts    public void OnTransferStarted() {}    // Action when the transfer progress changes    public Task OnProgressChangedAsync(FileTransferProgress fileTransferProgress) {}    // Action when the file transfer completes    public void OnTransferCompleted(long duration) {}    // Action when an exception occurs during the file transfer    public void OnTransferFailed(Exception exception) {}}

To enable this handler in your application, register the CustomFileTransferEventHandler service in the Startup.cs or Program.cs file:

cs
services.TryAddSingleton<CustomFileTransferEventHandler>();

Next, you can specify this handler when building the HTTP request:

cs
HttpRequestBuilder.DownloadFile("https://furion.net/img/furionlogo.png", @"C:\Workspaces\")    .SetEventHandler<CustomFileTransferEventHandler>();HttpRequestBuilder.DownloadFile("https://furion.net/img/furionlogo.png", @"C:\Workspaces\")    .SetEventHandler(typeof(CustomFileTransferEventHandler));    // Set using the type approach