![](/img/trans.png)
[英]Cannot read zip file from HttpInputStream using DotNetZip 1.9
[英]Cannot read that as a zip file using DotNetZip 1.9
我正在使用一個應用程序,它將從服務器上下載.zip文件並在使用DotNetZip 1.9下載完成后將其解壓縮。
該應用程序正在正確下載zip文件,但是當它進入讀取.zip文件的部分時,將引發異常“無法將其作為zip文件讀取”(位於http://pastebin.com/NTrtMgR9的完整異常)。
是什么讓我失望,甚至引發異常,文件仍正確解壓縮...
這是我的資料來源:
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);
HCZipPath = Path.Combine(Arma2OAPath, @"HardCorps.zip");
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()), HCZipPath);// " "
//extract
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
和我的ProgressChanged / Completed方法:
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
pbDownloader.Value = e.ProgressPercentage;//setting the progressbar value as downloadprogress
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
using (var zipFile = ZipFile.Read(String.Format(HCZipPath)))
{
zipFile.ExtractAll(Arma2OAPath, ExtractExistingFileAction.OverwriteSilently);
}
MessageBox.Show("Downloading Successful ", "Download_Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);//just a messagebox
pbDownloader.Value = (0);//resetting the progressbar
}
HCZipPath是一個字符串變量(如果有任何區別)
在btnDownload_Click
方法中,您嘗試在下載文件之前提取文件。 您調用Download_Client.DownloadFileAsync
開始下載,並且您已經正確設置了DownloadFileCompleted
事件的處理程序(嘗試再次進行提取)。 取出DownloadFileAsync
方法調用下面的代碼(以防止發生異常)。 正在提取文件,因為您是使用Completed
方法(這是正確的方法)提取文件的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.