您好,我試圖通過c#上傳一個文件到我的web服務器上,當我上傳文件時出現問題我的應用程序凍結,直到文件完成上傳,我想要上傳異步但我似乎無法讓代碼在這裏工作,有代碼和我不斷收到的錯誤。將上傳文件轉換爲uploadfileasync c#
此代碼有效,但會凍結表單。
WebClient wc = new WebClient();
wc.Credentials = new System.Net.NetworkCredential(TxtUsername.Text, TxtPassword.Text);
string Filename = TxtFilename.Text;
string Server = TxtServer.Text + SafeFileName.Text;
wc.UploadFile(Server, Filename);
但是,如果我這樣做的代碼,我會得到一個錯誤。
WebClient wc = new WebClient();
wc.Credentials = new System.Net.NetworkCredential(TxtUsername.Text, TxtPassword.Text);
string Filename = TxtFilename.Text;
string Server = TxtServer.Text + SafeFileName.Text;
wc.UploadFileAsync(Server, Filename);
和當試圖使它異步
Error 1 The best overloaded method match for System.Net.WebClient.UploadFileAsync(System.Uri, string)' has some invalid arguments.
Error 2 Argument 1: cannot convert from 'string' to 'System.Uri'
謝謝!非常!! – Terrii