logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • How to save report in HTML into ZIP
  • How to use Online Designer in ASP .NET Core

    January 17, 2018

    One of the novelties by FastReport .NET 2018 was the adaptation of OnlineDesigner to the

    read more
  • Copying the Bands from One Report to Another with All the Contents

    March 31, 2021

    Sometimes there is a need to use parts of one report in another. In simple

    read more
  • How to use WebReport with ASP .NET Web Core application

    January 17, 2018

    Recently FastReport introduced a new library under the .NET - FastReport Core platform. This is

    read more
  • FastReport .NET packages and .NET 5.0

    December 17, 2020

    UPD: Applies to the versions of FastReport .NET before 2022.2. License packages are now available

    read more
  • HTML 4.0 and CSS in the report – Simple! Review of the new "HTMLView" report object.

    May 26, 2021

    With a great variety of document formats, often can be a

    read more

How to save report in HTML into ZIP

April 13, 2016

When I was developing another PHP application, it was necessary in the financial statements. Previously I'd had great experience with FastReport.Net report generator. So I decided to use it for this purpose too. Unfortunately, the option with the Web-based reporting was irrelevant since we did not use ASP .Net in this project. The idea was born to use a REST web service that will build a report and give it to a php application. I will explain development of the service later. And now let's focus on the process of report building and preparation to be sent via REST. For simplicity, I'll demonstrate it on an example of a console application.

We need FastReport libraries:

1
2
3
using FastReport;
using FastReport.Export.Html;
using FastReport.Utils;

 I will pass the report title via the parameter:

1
2
3
4
5
6
7
 static void Main(string[] args)
 {
 if (args.Length > 0)
 DoExport(args[0]);
 else
 Console.WriteLine("Set the report file (*.frx) as parameter");
 }

Create the method of exporting report to HTML and archiving in ZIP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
private static void DoExport(string reportFile)
 {
 if (File.Exists(reportFile))
 {
 Config.WebMode = true; // set WebReport mode for disable all progress and enable thread-safe code
 using (Report report = new Report()) // create new report object
 {
 report.Load(reportFile); // load report from file
 report.Prepare(); // prepare report
 using (HTMLExport html = new HTMLExport()) // create new export object
 {
 html.SaveStreams = true; // enable saving in streams
 report.Export(html, (Stream)null); // set target stream in null - we have multiple streams inside export object
 if (html.GeneratedFiles.Count > 0)
 {
 ZipArchive zip = new ZipArchive(); // create ZIP object
 for(int i = 0; i < html.GeneratedFiles.Count; i++)
 zip.AddStream(html.GeneratedFiles[i], html.GeneratedStreams[i]); // add streams with file names in zip
 zip.SaveToFile(Path.GetFileNameWithoutExtension(reportFile) + ".zip"); // write zip in file
 }
 } 
 }
 }
 else
 Console.WriteLine("File " + reportFile + " not found!");
 }

Here it should be noted about Config.WebMode property - it enables the "quiet" mode of reporting without issuing any dialogs and progress bars.

In this example I pack one report, but there's no reason why not to put a few pieces in archive.

Now start the application in the console with the parameter. The parameter specifies the path to the report. And get a zip-file in the folder with the application. The archive is a packed report in html format. Thus, using a web service we can pass into our web application an archive with one or more reports.

 

about product download buy
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.NET FastReport HTML

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Contact us

© 1998-2022 by Fast Reports Inc.

  • Privacy Policy