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:
- Adding an ActiveReport to a Visual Studio project
- Adding code to the Web Form to create the PDF, HTML, Excel, Word and Image Export objects and export a report
- Running the project
To add an ActiveReport to the Visual Studio project
- Create a new Visual Studio Web Application project.
- From the Project menu, select Add New Item.
- In the Add New Item dialog that appears, select ActiveReports 7 Page Report and in the Name field, rename the file as CustomWebExporting.
- Click the Add button to open a new fixed page report in the designer.
- In the Solution Explorer, right-click the References node and select Add Reference.
- 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.
To add code to the Web Form to create the PDF Export object and export a report
- Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
- Add code like the following to the Page_Load event.
To 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() |
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.
|
Warning: You need to manually license your application in order to use PDF export. |
To add code to the Web Form to create the HTML Export object and export a report
- Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
- Add code like the following to the Page_Load event.
To 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() |
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(); |
To 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. |
- Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
- Add code like the following to the Page_Load event.
To 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() |
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(); |
To add code to the Web Form to create the Word Export object and export a report
- Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
- Add code like the following to the Page_Load event.
To 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() |
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(); |
To add code to the Web Form to create the Image Export object and export a report
- Double-click on the design view of the aspx page. This creates an event-handling method for the Page_Load event.
- Add code like the following to the Page_Load event.
To 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() |
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(); |
Press F5 to run the project.