如何从 UploadFileCompletedEventArgs 获取文件名?

How to get filename from UploadFileCompletedEventArgs?

我的目标是从 e.

获取完成文件的文件名
...
WebClient webClient = new WebClient();
webClient.UploadFileAsync(new Uri(address, "STOR", filename));
...

    void WebClientUploadCompleted(object sender, UploadFileCompletedEventArgs e)
    {
        //How to get filename from e?
    }

UploadFileAsync 接受用户状态作为第四个参数。因此,您可以将调用更改为:

webClient.UploadFileAsync(new Uri(address), "STOR", filename, filename);

并在回调中检索它:

void WebClientUploadCompleted(object sender, UploadFileCompletedEventArgs e)
{
    var filename = (string)e.UserState;
}