How do I generate and send a .zip file to a user in C# ASP.NET?

后端 未结 7 1077
感动是毒
感动是毒 2020-12-05 11:30

I need to construct and send a zip to a user.

I\'ve seen examples doing one or the other, but not both, and am curious if there are any \'best practices\' or anythin

7条回答
  •  爱一瞬间的悲伤
    2020-12-05 12:13

    I would second the vote for SharpZipLib to create the Zip file. Then you'll want to append a response header to the output to force the download dialog.

    http://aspalliance.com/259

    should give you a good starting point to achieve that. You basically need to add a response header, set the content type and write the file to the output stream:

    Response.AppendHeader( "content-disposition", "attachment; filename=" + name );
    Response.ContentType = "application/zip";
    Response.WriteFile(pathToFile);
    

    That last line could be changed to a Response.Write(filecontents) if you don't want to save to a temp file.

提交回复
热议问题