UploadFileCompletedEventArgs 类

定义

UploadFileCompleted 事件提供数据。

public ref class UploadFileCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class UploadFileCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type UploadFileCompletedEventArgs = class
    inherit AsyncCompletedEventArgs
Public Class UploadFileCompletedEventArgs
Inherits AsyncCompletedEventArgs
继承
UploadFileCompletedEventArgs

示例

下面的代码示例演示如何异步上传文件。

// Sample call: UploadFileInBackground2("http://www.contoso.com/fileUpload.aspx", "data.txt")
void UploadFileInBackground2( String^ address, String^ fileName )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   client->UploadFileCompleted +=
     gcnew UploadFileCompletedEventHandler (UploadFileCallback2);

   // Specify a progress notification handler.
   client->UploadProgressChanged +=
       gcnew UploadProgressChangedEventHandler( UploadProgressCallback );
   client->UploadFileAsync( uri, "POST", fileName );
   Console::WriteLine( "File upload started." );
}
// Sample call: UploadFileInBackground2("http://www.contoso.com/fileUpload.aspx", "data.txt")
public static void UploadFileInBackground2(string address, string fileName)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);

    client.UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCallback2);

    // Specify a progress notification handler.
    client.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback);
    client.UploadFileAsync(uri, "POST", fileName);
    Console.WriteLine("File upload started.");
}
'  Sample call: UploadFileInBackground2("http:' www.contoso.com/fileUpload.aspx", "data.txt")
Public Shared Sub UploadFileInBackground2(ByVal address As String, ByVal fileName As String)

    Dim client As WebClient = New WebClient()
                Dim uri as Uri =  New Uri(address)
    AddHandler client.UploadFileCompleted, AddressOf UploadFileCallback2

    '  Specify a progress notification handler.
    AddHandler client.UploadProgressChanged, AddressOf UploadProgressCallback
    client.UploadFileAsync(uri, "POST", fileName)
    Console.WriteLine("File upload started.")
End Sub

上传完成后,将调用以下方法。

void UploadFileCallback2( Object^ /*sender*/, UploadFileCompletedEventArgs^ e )
{
   String^ reply = System::Text::Encoding::UTF8->GetString( e->Result );
   Console::WriteLine( reply );
}
private static void UploadFileCallback2(Object sender, UploadFileCompletedEventArgs e)
{
    string reply = System.Text.Encoding.UTF8.GetString(e.Result);
    Console.WriteLine(reply);
}
Private Shared Sub UploadFileCallback2(ByVal sender As Object, ByVal e As System.Net.UploadFileCompletedEventArgs)

    Dim reply As String = System.Text.Encoding.UTF8.GetString(e.Result)
    Console.WriteLine(reply)
End Sub

注解

此类的实例将传递给 UploadFileCompletedEventHandler

属性

Cancelled

获取一个值,该值指示异步操作是否已被取消。

(继承自 AsyncCompletedEventArgs)
Error

获取一个值,该值指示异步操作期间发生的错误。

(继承自 AsyncCompletedEventArgs)
Result

获取通过调用 UploadFileAsync 方法启动的数据上载操作的服务器回复。

UserState

获取异步任务的唯一标识符。

(继承自 AsyncCompletedEventArgs)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
RaiseExceptionIfNecessary()

如果异步操作失败,则引发用户提供的异常。

(继承自 AsyncCompletedEventArgs)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于