简体   繁体   English

在内存中下载zip +文件

[英]Download zip + file in memory

I tried searching some topics but not found the solution to the problem. 我尝试搜索一些主题,但没有找到问题的解决方案。 Someone explain to me why my txt is coming empty? 有人向我解释为什么我的txt会变空?

  this.Response.Clear();
  this.Response.ContentType = "application/x-zip-compressed";
  this.Response.AppendHeader("content-disposition", "attachment; filename=Outro.zip");

  System.IO.FileStream reader = File.OpenRead(@"C:\Teste\Teste.txt");
  byte[] bytes = new byte[reader.ReadByte()];  
  using (ZipFile zipFile = new ZipFile())
  {

      using (MemoryStream stream = new MemoryStream())
       {

         stream.Seek(0, SeekOrigin.Begin);
         stream.Read(bytes, 0, bytes.Length);
         zipFile.AddEntry("Arquivo.txt", stream);
         zipFile.Save(this.Response.OutputStream);

       }

       zipFile.Dispose();
   }

 }

ReadByte() reads a single byte! ReadByte()读取一个字节!

Take a look at the example here FileStream.Read() 看看这里的例子FileStream.Read()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM