在内存中下载zip +文件

时间:2013-06-17 04:06:34

标签: c#

我尝试搜索某些主题但未找到问题的解决方案。有人向我解释为什么我的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();
   }

 }

1 个答案:

答案 0 :(得分:3)

ReadByte()读取一个字节!

看一下FileStream.Read()

中的示例