logo
small logo
  • Products
  • Buy
  • Support
  • About
  • Customer panel Support
    • en
    • de
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • How to save report in HTML into ZIP
  • The era of WinForms is over, the era of FastReport.Core.Skia began

    September 6, 2022

    To create high-quality reports and correctly export them to different formats (PDF, Word, Excel, etc.),

    read more
  • Reports and PDF documents in Blazor

    April 5, 2021

    Microsoft has recently launched a web platform called Blazor. This framework allows creating an interactive

    read more
  • How to install FastReport Business Graphics .NET

    August 18, 2021

    This article shows how to install FastReport Business Graphics .NET on your computer and how

    read more
  • Report generators family FastReport brief review

    March 23, 2020

    Without reporting it is impossible to carry on business in any sphere of life. Bureaucracy

    read more
  • Create a new report with code VB.NET

    September 17, 2020

    Speaking of the .Net framework, we usually imagine the #C programming language. Simply because the

    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 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
  • FAQ
  • Tutorial Video
  • Forum
  • Support SLA
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Extended licensing
  • Contact us

© 1998-2023 by Fast Reports Inc.

  • Privacy Policy

Trustpilot