ASP.NET Download All Files as Zip

后端 未结 4 434
不知归路
不知归路 2020-12-14 12:31

I have a folder on my web server that has hundreds of mp3 files in it. I would like to provide the option for a user to download a zipped archive of every mp3 in the directo

4条回答
  •  我在风中等你
    2020-12-14 13:26

    I can't believe how easy this was. After reading this, here is the code that I used:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        Response.BufferOutput = false;
        Response.ContentType = "application/zip";
        Response.AddHeader("content-disposition", "attachment; filename=pauls_chapel_audio.zip");
    
        using (ZipFile zip = new ZipFile())
        {
            zip.CompressionLevel = CompressionLevel.None;
            zip.AddSelectedFiles("*.mp3", Server.MapPath("~/content/audio/"), "", false);
            zip.Save(Response.OutputStream);
        }
    
        Response.Close();
    }
    

提交回复
热议问题