Tag: dotnetzip

使用DotNetZip从zip中提取特定文件夹

我一直在搜索示例,但似乎无法找到涉及提取某个文件夹的DotNetZip场景。 我正在尝试从.zip文件中提取名为“CSS”的文件夹,它是.zip文件中的顶级文件夹。 这是我到目前为止的代码: using (ZipFile zip1 = ZipFile.Read(savedFileName)) { var selection = from e in zip1.Entries where System.IO.Path.GetFileName(e.FileName).StartsWith(“CSS/”) select e; foreach (var e in selection) e.Extract(_contentFolder); } 当前选择什么都没有,我可以使用一些帮助重写它,以便它提取css文件夹及其所有子目录和文件。

使用C#上传到服务器后,Zip文件已损坏

我正在尝试使用C# (Framework 4) 将zip文件上传到服务器,以下是我的代码。 string ftpUrl = ConfigurationManager.AppSettings[“ftpAddress”]; string ftpUsername = ConfigurationManager.AppSettings[“ftpUsername”]; string ftpPassword = ConfigurationManager.AppSettings[“ftpPassword”]; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUrl + “Transactions.zip”); request.Proxy = new WebProxy(); //—–The requested FTP command is not supported when using HTTP proxy. request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(ftpUsername, ftpPassword); StreamReader sourceStream = new StreamReader(fileToBeUploaded); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); […]

使用ASP.NET Web API,控制器如何返回使用DotNetZip Library压缩的流图像集合?

如何创建Web API控制器,生成并返回从内存中JPEG文件(MemoryStream对象)集合流式传输的压缩zip文件。 我正在尝试使用DotNetZip库。 我找到了这个例子: http : //www.4guysfromrolla.com/articles/092910-1.aspx#postadlink 。 但是,Response.OutputStream在Web API中不可用,因此该技术不能正常工作。 因此我尝试将zip文件保存到新的MemoryStream中; 但它扔了。 最后,我尝试使用PushStreamContent。 这是我的代码: public HttpResponseMessage Get(string imageIDsList) { var imageIDs = imageIDsList.Split(‘,’).Select(_ => int.Parse(_)); var any = _dataContext.DeepZoomImages.Select(_ => _.ImageID).Where(_ => imageIDs.Contains(_)).Any(); if (!any) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } var dzImages = _dataContext.DeepZoomImages.Where(_ => imageIDs.Contains(_.ImageID)); using (var zipFile = new ZipFile()) { foreach […]

Ionic.Zip库无法提取.rar文件C#

我试图使用.net zip库(Ionic.Zip.dll)提取.rar文件。 我在执行以下代码时遇到错误“ 无法读取为zipfile ”; using (ZipFile zip1 = ZipFile.Read(“E:\\APPS\\package.rar”)){ } 我知道错误是自解释的,但Ionic.Zip的文档说它可以用来提取.rar文件。 有任何想法吗?

可以使用MemoryStream和FileStreamResult吗?

我正在使用DotNetZip创建一个zip文件并将其传递给FileResult。 在调试时,我可以validationMemoryStream是否包含文件,但是当我通过FileStreamResult运行它时,它返回0bytes: public FileResult GetZipFiles(int documentId) { var file = fileRepository.Get(documentId); var zip = new ZipFile(); var stream = new MemoryStream(); var filePath = Path.Combine(UploadsFolder, Path.GetFileName(file.Id)); zip.AddFile(filePath); zip.Save(stream); var result = new FileStreamResult(stream, “application/zip”) { FileDownloadName = “hey.zip” }; return result; } 同样,我可以validation流不是空的,但这将始终将文件hey.zip返回为0bytes。 我必须在这里使用MemoryStream错误吗? 或者FileStreamResult做了一些我不希望它做的事情? 我之前使用过FileStreamResult ,但没有使用MemoryStream 。

C#:如何在创建zip文件时报告进度?

更新:让它工作更新我的工作代码 这是我到目前为止所拥有的 private async void ZipIt(string src, string dest) { await Task.Run(() => { using (var zipFile = new ZipFile()) { // add content to zip here zipFile.AddDirectory(src); zipFile.SaveProgress += (o, args) => { var percentage = (int)(1.0d / args.TotalBytesToTransfer * args.BytesTransferred * 100.0d); // report your progress pbCurrentFile.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action( delegate() { pbCurrentFile.Value […]

DotNetZip – 在C#中调用Save(stream)之前计算最终的zip大小

使用DotNetZip时,是否可以在调用Save(流)之前获得最终的zip文件大小? 我有一个应用程序(Window Service),其中包的Stream大小超过100MB,然后将保存包并将即将发布的文件添加到新包中。 我对Web应用程序有同样的问题,但不理解答案。 在保存在I / O系统之前,是否有任何方法可以在DotnetZip中找到zip流的大小?

使用DotNetZip通过ASP.NET MVC下载zip文件

我在文件夹中创建了一个文本文件并压缩了该文件夹并保存了@same位置以供测试。 我想在创建后直接在用户计算机上下载该zip文件。 我正在使用dotnetzip库并完成以下操作: Response.Clear(); Response.ContentType = “application/zip”; Response.AddHeader(“content-disposition”, “filename=” + “sample.zip”); using (ZipFile zip = new ZipFile()) { zip.AddDirectory(Server.MapPath(“~/Directories/hello”)); zip.Save(Server.MapPath(“~/Directories/hello/sample.zip”)); } 有人可以建议如何在用户端下载zip文件。