WebClient DownloadFileAsync()工作Incorect

时间:2018-03-01 23:58:44

标签: c# webclient downloadfileasync

我使用WebClient从服务器下载文件,但下载的文件不相同(文件大小错误):

这是截图(下载的文件在右侧):

Downloaded file

这是我的代码:

public void StartDownload(string fileToDownloadLink, string PathToSaveFile)         ///////// Try check file type..
    {
        try
        {
            using (webClient = new WebClient())
            {
                //webClient.Encoding = Encoding.UTF8;
                webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Client_DownloadFileCompleted);
                webClient.DownloadFileAsync(new Uri(fileToDownloadLink), PathToSaveFile);
            }
        }
        catch (WebException e)
        {
            MessageBox.Show(fileToDownloadLink);
            MessageBox.Show(e.ToString());
            Worker.CancelAsync();
            Application.Exit();
        }
    }

怎么了?

1 个答案:

答案 0 :(得分:0)

我可能会发现为什么会这样。服务器支持上传到服务器后只有ASCII编码查看文件大小: enter image description here

我强制编码并且工作正常:)现在文件是相同的:)