ActiveReports Developer 7 > ActiveReports Developer Guide > Samples and Walkthroughs > Walkthroughs > Page Report Walkthroughs > Custom Web Exporting in a Page Report |
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:
To add an ActiveReport to the Visual Studio 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
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() |
To 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.
|
![]() |
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
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() |
To 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(); |
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. |
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() |
To 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(); |
To add code to the Web Form to create the Word Export object and export a report
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() |
To 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(); |
To add code to the Web Form to create the Image Export object and export a report
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() |
To 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(); |
To run the project
Press F5 to run the project.