public static void GenerateReportToHttpResponseAsZipArchive(IEnumerable <ReportParameters> parametersCollection, string zipFileName, Encoding encoding) { if (parametersCollection == null) { throw new ArgumentNullException("parametersCollection"); } HttpContext context = HttpContext.Current; if (context == null) { throw new InvalidOperationException("HttpContext is not present."); } HttpResponse resp = context.Response; resp.Clear(); //resp.ContentEncoding = encoding; try { ZipFile zf = new ZipFile(); foreach (ReportParameters parameters in parametersCollection) { StringWriterEx sw = new StringWriterEx(encoding); GenerateReport(parameters, sw); zf.AddFileWithContent(parameters.TargetFilePathParts, sw.ToString(), encoding); } parametersCollection = null; byte[] zipBytes = zf.SaveToBytes(); resp.BinaryWrite(zipBytes); if (context.Request.Browser.Browser == "IE") { resp.ContentType = ContentTypes.OctetStream; } else { resp.ContentType = ContentTypes.Zip; } if (string.IsNullOrEmpty(zipFileName) == false) { AddContentDispositionHeader(zipFileName); } } catch (Exception) { resp.Clear(); throw; } resp.End(); }
public static void GenerateReportToHttpResponseAsZipArchive(IEnumerable<ReportParameters> parametersCollection, string zipFileName, Encoding encoding) { if (parametersCollection == null) throw new ArgumentNullException("parametersCollection"); HttpContext context = HttpContext.Current; if (context == null) throw new InvalidOperationException("HttpContext is not present."); HttpResponse resp = context.Response; resp.Clear(); //resp.ContentEncoding = encoding; try { ZipFile zf = new ZipFile(); foreach (ReportParameters parameters in parametersCollection) { StringWriterEx sw = new StringWriterEx(encoding); GenerateReport(parameters, sw); zf.AddFileWithContent(parameters.TargetFilePathParts, sw.ToString(), encoding); } parametersCollection = null; byte[] zipBytes = zf.SaveToBytes(); resp.BinaryWrite(zipBytes); if (context.Request.Browser.Browser == "IE") resp.ContentType = ContentTypes.OctetStream; else resp.ContentType = ContentTypes.Zip; if (string.IsNullOrEmpty(zipFileName) == false) AddContentDispositionHeader(zipFileName); } catch (Exception) { resp.Clear(); throw; } resp.End(); }