1

I need to get multiple excel files (SSRS reports), put them in folder and zip it. This is how I tried, but it's not working:

public ActionResult PricingReports( List<int> productIds )
{
    MemoryStream memStream = new MemoryStream();
    using ( ZipArchive archive = new ZipArchive( memStream, ZipArchiveMode.Update ) )
    {
        foreach ( int id in productIds )
        {
            //preparing single excel file
            ReportModel model = PrepareReportModel( values );

            _ssrs.GetReport( model, "EXCEL" );

            ZipArchiveEntry singleReport = archive.CreateEntry( "PricingReport" + " - " + id );
            using ( BinaryWriter binWriter = new BinaryWriter( singleReport.Open() ) )
            {
                binWriter.Write( model.ReportBits );
            }
        }
    }
    return File( memStream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Octet, "Pricing reports" );
}
bambi
  • 1,159
  • 2
  • 14
  • 31
  • You could place the files in a directory and use the ZipFile class. Its a newer feature introduced in .NET 4.5 https://msdn.microsoft.com/en-us/library/hh485707(v=vs.110).aspx – Cody Hicks Jan 07 '16 at 16:42
  • Based on your code, I see you may be using MVC. If its returning the file you are having difficulties with, see the answer to this question.. http://stackoverflow.com/questions/29907291/downloading-of-zip-file-through-asp-net-mvc-using-dotnetzip The same method of returning the zip file could be used regardless of what class or lib you use to zip the files. – Cody Hicks Jan 07 '16 at 16:53

0 Answers0