使用C#中的阅读器下载zip文件 [英] download zip files by use of reader in c#
问题描述
我一直在研究此应用程序,该应用程序使用户可以登录到另一个网站,然后从该服务器下载指定的文件.到目前为止,我已经成功登录了网站并下载了文件.但是当涉及到zip文件时,一切都毁了.
是否有任何代码块有助于逐字节读取.zip文件或使用流读取器?
我正在使用
I have been working on this application that enables user to log in into another website, and then download specified file from that server. So far I have succeeded in logging on the website and download the file. But everything ruins when it comes to zip files.
Is there any chunk of code that could be helpful in reading the .zip files byte by byte or by using stream reader?
I m using
WebClient.DownloadFile()
,但未返回正确的zip文件.
我需要一种可以读取zip文件的方法.我可以使用
but its not returning the correct zip file.
I need a method by which I can read zip files. Can I do it by using
ByteReader()
做到吗
预先感谢.
Thanks in advance.
推荐答案
WebClient client = new WebClient();
client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(client_DownloadDataCompleted);
client.DownloadDataAsync(new Uri("http://www.test.com/myzip.zip"), @"C\newfile.zip");
void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
// MessageBox.Show("File downloaded");
}
步骤1:
要将zip文件从另一台服务器下载到本地服务器
step 1:
To download zip file from another server to local server
string remoteFilePath = "http://yourdomain.com/test/aa.zip";
Uri remoteFilePathUri = new Uri(remoteFilePath);
string remoteFilePathWithoutQuery = remoteFilePathUri.GetLeftPart(UriPartial.Path);
string fileName = Path.GetFileName(remoteFilePathWithoutQuery);
string localPath = Server.MapPath("~") + @"test\" + fileName;
WebClient webClient = new WebClient();
webClient.DownloadFile(remoteFilePath, localPath);
webClient.Dispose();
步骤2:
通过网页从本地服务器下载文件
step 2:
To download file from local server by web page
Response.Clear();
Response.Charset = "";
Response.ContentType = "application/zip";
Response.AppendHeader("Content-Disposition", "attachment; filename=aa.zip");
Response.TransmitFile(localPath);
Response.Flush();
Response.End();
是否有任何代码块可以帮助阅读.zip文件是逐字节还是使用流读取器?
Is there any chunk of code that could be helpful in reading the .zip files byte by byte or by using stream reader?
上周,我只是使用ICSharpCode.SharpZipLib来查看Flash SWF文件,因为在大多数情况下,这些文件是压缩的.
我不记得我从哪里得到的,但这是免费下载的.它似乎可以处理几乎所有内容,包括zip,rar,tar和源代码.
我在下面这样使用它
I just used ICSharpCode.SharpZipLib last week to peek inside flash swf files, because most of the time, the files are compressed.
I can''t remember where I got it from, but it was a free download. It seems to handle almost everything, zip, rar, tar, and the source is available as well.
I used it like this below
Dim inputStream As Stream = Nothing
If (System.Text.Encoding.ASCII.GetString(signature, 0, 3) = "CWS") Then
inputStream = New InflaterInputStream(stream)
Else
inputStream = stream
End If
这篇关于使用C#中的阅读器下载zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!