ActiveReports Developer 7
Custom Web Exporting in a Page Report
See Also Support Forum
ActiveReports Developer 7 > ActiveReports Developer Guide > Samples and Walkthroughs > Walkthroughs > Page Report Walkthroughs > Custom Web Exporting in a Page Report

Glossary Item Box

ActiveReports Developer provides components that allow you to export your reports into several popular formats like PDF, HTML, Excel, Image and Word.

The walkthrough is split up into the following activities:

ShowTo add an ActiveReport to the Visual Studio project

  1. Create a new Visual Studio Web Application project.
  2. From the Project menu, select Add New Item.
  3. In the Add New Item dialog that appears, select ActiveReports 7 Page Report and in the Name field, rename the file as CustomWebExporting.
  4. Click the Add button to open a new fixed page report in the designer.
  5. In the Solution Explorer, right-click the References node and select Add Reference.
  6. In the Add Reference dialog that appears, select the following references and click OK to add them to your project.
    GrapeCity.ActiveReports.Export.Pdf.v7
    GrapeCity.ActiveReports.Export.Html.v7
    GrapeCity.ActiveReports.Export.Excel.v7
    GrapeCity.ActiveReports.Export.Word.v7
    GrapeCity.ActiveReports.Export.Image.v7

See Adding an ActiveReport to a Project for information on adding different report layouts.

ShowTo add code to the Web Form to create the PDF Export object and export a report

  1. Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
  2. Add code like the following to the Page_Load event.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Page Load event. Copy Code
Dim _reportDef As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim _reportRuntime As New GrapeCity.ActiveReports.Document.PageDocument(_reportDef)

'Set the rendering extension and render the report.
Dim _renderingExtension As New GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension()
Dim _provider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
_reportRuntime.Render(_renderingExtension, _provider)

Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf")
Dim ms As New System.IO.MemoryStream()
CType(_provider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.End()

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
_reportRuntime.Render(_renderingExtension, _provider);

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
_provider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();            

Note: To use the one-touch printing option, add the following to the code above.

Visual Basic.NET code. Paste INSIDE the Page Load event. Copy Code
' Replace the line _reportRuntime.Render(_renderingExtension, _provider) in the code above with the following

Dim s As New GrapeCity.ActiveReports.Export.Pdf.Page.Settings()
s.PrintOnOpen = True
_reportRuntime.Render(_renderingExtension, _provider,s)
C# code. Paste INSIDE the Page Load event. Copy Code
// Replace the line _reportRuntime.Render(_renderingExtension, _provider); in the code above with the following

GrapeCity.ActiveReports.Export.Pdf.Page.Settings s = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
s.PrintOnOpen = true;
_reportRuntime.Render(_renderingExtension, _provider,s);
Warning: You need to manually license your application in order to use PDF export.

 

ShowTo add code to the Web Form to create the HTML Export object and export a report

  1. Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
  2. Add code like the following to the Page_Load event.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Page Load event. Copy Code
Dim _reportDef As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim _reportRuntime As New GrapeCity.ActiveReports.Document.PageDocument(_reportDef)

' Set the rendering extension and render the report.
Dim _renderingExtension As New GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension()
Dim _provider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
Dim s As New GrapeCity.ActiveReports.Export.Html.Page.Settings()
s.Mode = GrapeCity.ActiveReports.Export.Html.Page.RenderMode.Galley
s.MhtOutput = True

_reportRuntime.Render(_renderingExtension, _provider, s)

Response.ContentType = "message/rfc822"
Response.AddHeader("content-disposition", "inline;filename=MyExport.mht")
Dim ms As New System.IO.MemoryStream()
CType(_provider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.End()   

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
GrapeCity.ActiveReports.Export.Html.Page.Settings s = new GrapeCity.ActiveReports.Export.Html.Page.Settings(); s.Mode = GrapeCity.ActiveReports.Export.Html.Page.RenderMode.Galley; s.MhtOutput = true; _reportRuntime.Render(_renderingExtension, _provider,s); Response.ContentType = "message/rfc822"; Response.AddHeader("content-disposition", "inline;filename=MyExport.html"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); _provider.GetPrimaryStream().OpenStream().CopyTo(ms); Response.BinaryWrite(ms.ToArray()); Response.End();

ShowTo add code to the Web Form to create the Excel Export object and export a report

Note: Convert your report layout to CPL in order to render it to an Excel format.
  1. Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
  2. Add code like the following to the Page_Load event.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Page Load event. Copy Code
Dim _reportDef As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim _reportRuntime As New GrapeCity.ActiveReports.Document.PageDocument(_reportDef)

' Set the rendering extension and render the report.
Dim _renderingExtension As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice()
Dim _provider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
Dim s As New GrapeCity.ActiveReports.Export.Excel.Page.Settings()
s.ProtectWorkbookPassword = 123

_reportRuntime.Render(_renderingExtension, _provider, s)

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "inline;filename=MyExport.xls")
Dim ms As New System.IO.MemoryStream()
CType(_provider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.End()   

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice _renderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
GrapeCity.ActiveReports.Export.Excel.Page.Settings s = new GrapeCity.ActiveReports.Export.Excel.Page.Settings();
s.ProtectWorkbookPassword = "123";

_reportRuntime.Render(_renderingExtension, _provider, s);

Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "inline;filename=MyExport.xls");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
_provider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();            

ShowTo add code to the Web Form to create the Word Export object and export a report

  1. Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
  2. Add code like the following to the Page_Load event.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Page Load event. Copy Code
Dim _reportDef As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim _reportRuntime As New GrapeCity.ActiveReports.Document.PageDocument(_reportDef)

' Set the rendering extension and render the report.
Dim _renderingExtension As New GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension()
Dim _provider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
Dim s As New GrapeCity.ActiveReports.Export.Word.Page.Settings()
s.UseMhtOutput = True

_reportRuntime.Render(_renderingExtension, _provider, s)

Response.ContentType = "application/msword"
Response.AddHeader("content-disposition", "inline;filename=MyExport.doc")
Dim ms As New System.IO.MemoryStream()
CType(_provider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.End()   

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
GrapeCity.ActiveReports.Export.Word.Page.Settings s = new GrapeCity.ActiveReports.Export.Word.Page.Settings();            
s.UseMhtOutput = true;

_reportRuntime.Render(_renderingExtension, _provider, s);

Response.ContentType = "application/msword";
Response.AddHeader("content-disposition", "inline;filename=MyExport.doc");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
_provider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();            

ShowTo add code to the Web Form to create the Image Export object and export a report

  1. Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
  2. Add code like the following to the Page_Load event.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Page Load event. Copy Code
Dim _reportDef As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx"))
Dim _reportRuntime As New GrapeCity.ActiveReports.Document.PageDocument(_reportDef)

' Set the rendering extension and render the report.
Dim _renderingExtension As New GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension()
Dim _provider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider()
Dim s As New GrapeCity.ActiveReports.Export.Image.Page.Settings()
s.ImageType = GrapeCity.ActiveReports.Export.Image.Page.Renderers.ImageType.JPEG

_reportRuntime.Render(_renderingExtension, _provider, s)

Response.ContentType = "image/jpeg"
Response.AddHeader("content-disposition", "inline;filename=MyExport.jpg")
Dim ms As New System.IO.MemoryStream()

' Get the first page of the report
CType(_provider.GetSecondaryStreams()(0).OpenStream(), System.IO.MemoryStream).WriteTo(ms)
Response.BinaryWrite(ms.ToArray())
Response.End() 

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx"));
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
GrapeCity.ActiveReports.Export.Image.Page.Settings s = new GrapeCity.ActiveReports.Export.Image.Page.Settings();
s.ImageType = GrapeCity.ActiveReports.Export.Image.Page.Renderers.ImageType.JPEG;      

_reportRuntime.Render(_renderingExtension, _provider, s);

Response.ContentType = "image/jpeg";
Response.AddHeader("content-disposition", "inline;filename=MyExport.jpg");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
// Get the first page of the report
_provider.GetSecondaryStreams()[0].OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();           

ShowTo run the project

Press F5 to run the project.

See Also

©2014. ComponentOne, a division of GrapeCity. All rights reserved.