从服务器下载文件(不下载?)

我目前正在使用一个需要按钮的客户端,该按钮将检查目录以查看其中是否存在特定文件夹,如果不存在,则它将从我的Web服务器下载.zip文件,并在完成下载后解压缩.zip文件。到目录。

由于某种原因,应用程序返回它已完成,但是根本不下载任何内容。我使用在网上找到的教程来进行此修改http://www.ultimateprogrammingtutorials.info/2013/06/how-to-make-downloader-in-c.html)。

这是我的下载代码:

下载按钮:

private void btnDownload_Click(object sender, EventArgs e)
    {
        if (!Directory.Exists(HardCorpsPath))
        {
            //MessageBox.Show("Downloading HardCorps Mod Pack (Full)", "Downloading", MessageBoxButtons.OK, MessageBoxIcon.Information);
            zipFileName = "HardCorps";

            HCDownloadURL = String.Format("http://www.survivaloperations.net/client/hardcorps/{0}.zip", zipFileName);

            WebClient Download_Client = new WebClient();//Declaring the webclient as Download_Client
            Download_Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);//the event handler
            Download_Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);// " "
            Download_Client.DownloadFileAsync(new Uri(HCDownloadURL.Trim().ToString()), Arma2OAPath);// " "

            //extract zip
            HCZipPath = Path.Combine(Arma2OAPath, @"HardCorps.zip");

            using (var zipFile = ZipFile.Read(HCZipPath))
            {
                zipFile.ExtractAll(Arma2OAPath, ExtractExistingFileAction.OverwriteSilently);
            }


        }
        else
        {
            MessageBox.Show("Directory Validated!");
            //Read users HardCorpsPath\version.txt and compare to server version.txt
            //if server version > user version, download patch.zip where "patch" == the number version of the server's version.txt (ex: 1001.zip)
            //On download complete, extract to HardCorpsPath and overwrite silently
        }
    }//close Download Button

其余的部分:

private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        pbDownloader.Value = e.ProgressPercentage;//setting the progressbar value as downloadprogress
    }
    private void Completed(object sender, AsyncCompletedEventArgs e)
    {
        MessageBox.Show("Downloading Successful ", "Download_Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);//just a messagebox          
        pbDownloader.Value = (0);//resetting the progressbar
    }

在应用程序尝试解压缩不存在的文件之前,我没有收到任何错误。

相当迷茫和困惑,可以使用一组新鲜的眼睛来发现问题。

谢谢!

乔什·瓦蒂(JoshVarty)

您的问题很可能是您在传递文件路径DownloadFileAsync时应该传递文件名。

string fullFileName = Arma2OAPath + "test.zip";
Download_Client.DownloadFileAsync(new Uri(HCDownloadURL.Trim().ToString()), fullFileName );

另一个问题是DownloadFileAsync是非阻塞的。这意味着您可以立即开始解压缩文件,而无需等待文件下载。您应该将解压缩到Completed()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

从服务器下载文件(不下载?)

来自分类Dev

从服务器以html下载文件

来自分类Dev

DownloadFileAsync不下载文件

来自分类Dev

从FTP服务器下载文件时损坏文件

来自分类Dev

通过脚本从文件服务器下载文件

来自分类Dev

从服务器文件夹下载文件

来自分类Dev

Android-从服务器下载文件终止

来自分类Dev

在Android中使用IntentService从服务器下载文件

来自分类Dev

MVC从远程服务器下载文件

来自分类Dev

使用ASP MVC从远程服务器下载文件

来自分类常见问题

在React中如何从服务器下载文件?

来自分类Dev

JSP-允许用户从服务器下载文件

来自分类Dev

从基于Flask的Python服务器下载文件

来自分类Dev

使用Java从服务器下载文件

来自分类Dev

下载文件(如果服务器上存在)

来自分类Dev

使用angularjs从服务器下载文件

来自分类Dev

如何从服务器下载文件(sso和https)

来自分类Dev

使用Swift从服务器下载文件

来自分类Dev

从服务器Objective C或Swift下载文件

来自分类Dev

Ruby Net :: FTP-从服务器下载文件

来自分类Dev

通过网站从PHP服务器下载文件

来自分类Dev

从服务器Struts 2.0下载文件

来自分类Dev

php从其他服务器下载文件

来自分类Dev

如何从服务器或本地Xampp下载文件?的PHP

来自分类Dev

从服务器Laravel和reactjs下载文件

来自分类Dev

使用Flask和JS从服务器下载文件

来自分类Dev

在React中如何从服务器下载文件?

来自分类Dev

如何通过javascript从tomcat服务器下载文件?

来自分类Dev

如何在Windows服务器上下载文件?