0

我用来WebClient从服务器下载文件,但下载的文件不一样(文件大小错误):

这是一个截图(下载的文件在右边):

下载文件

这是我的代码:

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();
        }
    }

怎么了?

4

1 回答 1

0

我可能会找到发生这种情况的原因.. 上传到服务器后服务器仅支持 ASCII 编码查看文件大小: 在此处输入图像描述

我强制编码并且它起作用了:)现在文件是一样的:)

于 2018-03-02T13:17:45.597 回答