ActiveReports Developer 7
Custom Web Exporting (Std Edition)
Support Forum
ActiveReports Developer 7 > ActiveReports Developer Guide > Samples and Walkthroughs > Walkthroughs > Section Report Walkthroughs > Custom Web Exporting (Std Edition)

Glossary Item Box

ActiveReports provides components that allow you to set up report custom exporting to PDF, Excel, TIFF, RTF, and plain text formats. You can similarly export to HTML, or you can create a custom HTML outputter.

ShowTo add a report and export references to the Web project

  1. From the View menu, select Component Designer to go to the design view of the aspx file.
  2. From the Project menu, select Add New Item.
  3. In the Add New Item window that appears, select the ActiveReports 7 Section Report (xml-based) template, set the report's name to SectionReport1, and click the Add button.
  4. From the Project menu, select Add Reference.
  5. In the Add Reference dialog that appears, select the following references and click OK to add them to your project.
    GrapeCity.ActiveReports.Export.Pdf.v8
    GrapeCity.ActiveReports.Export.Html.v8
    GrapeCity.ActiveReports.Export.Excel.v8
    GrapeCity.ActiveReports.Export.Word.v8
    GrapeCity.ActiveReports.Export.Xml.v8
    GrapeCity.ActiveReports.Export.Image.v8
  6. Design your report.

ShowTo add code to the Web Form to export a report to PDF

  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 m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader("\SectionReport1.rpx")
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim PdfExport1 As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport
PdfExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=MyExport.pdf")
Response.BinaryWrite(m_stream.ToArray())
Response.End()

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
rpt.Run();
GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport pdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();
pdfExport1.Export(rpt.Document, m_stream);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf");
Response.BinaryWrite(m_stream.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
pdfExport1.Options.OnlyForPrint = True
C# code. Paste INSIDE the Page Load event. Copy Code
pdfExport1.Options.OnlyForPrint = true;

ShowTo add code to the Web Form to export a report to Excel

  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 m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader("\SectionReport1.rpx")
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim XlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport
XlsExport1.MinColumnWidth = 0.5
XlsExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "inline; filename=MyExport.xls")
Response.BinaryWrite(m_stream.ToArray())
Response.End()

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
rpt.Run();
GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
XlsExport1.MinColumnWidth = 0.5f; XlsExport1.Export(rpt.Document, m_stream); m_stream.Position = 0; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("content-disposition","inline; filename=MyExport.xls"); Response.BinaryWrite(m_stream.ToArray()); Response.End();

ShowTo add code to the Web Form to export a report to TIFF

  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 m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader(Server.MapPath("\SectionReport1.rpx"))
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim TiffExport1 As New GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport 
Me.TiffExport1.CompressionScheme = GrapeCity.ActiveReports.Export.Image.Tiff.Section.CompressionScheme.None 
Me.TiffExport1.Export(rpt.Document, m_stream)m_stream.Position = 0 
Response.ContentType = "image/tiff" 
Response.AddHeader("content-disposition", "inline; filename=MyExport.tiff")
Response.BinaryWrite(m_stream.ToArray())
Response.End()

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
rpt.Run();
GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport tiffExport1 = new GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport(); 
tiffExport1.CompressionScheme = GrapeCity.ActiveReports.Export.Image.Tiff.Section.CompressionScheme.None;
tiffExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "image/tiff";
Response.AddHeader("content-disposition","inline; filename=MyExport.tiff");
Response.BinaryWrite(m_stream.ToArray());
Response.End();

ShowTo add code to the Web Form to export a report to RTF

  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 m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader("\SectionReport1.rpx")
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim RtfExport1 As New GrapeCity.ActiveReports.Export.Word.Section.RtfExport
RtfExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "application/msword"
Response.AddHeader("content-disposition", "inline; filename=MyExport.rtf")
Response.BinaryWrite(m_stream.ToArray())
Response.End()

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
rpt.Run();
GrapeCity.ActiveReports.Export.Word.Section.RtfExport rtfExport1  = new GrapeCity.ActiveReports.Export.Word.Section.RtfExport(); 
rtfExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "application/msword";
Response.AddHeader("content-disposition","inline; filename=MyExport.rtf");
Response.BinaryWrite(m_stream.ToArray());
Response.End();

ShowTo add code to the Web Form to export a report to Plain Text

  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 m_stream As New System.IO.MemoryStream()
Dim rpt As New GrapeCity.ActiveReports.SectionReport
Dim xtr As New System.Xml.XmlTextReader("\SectionReport1.rpx")
rpt.LoadLayout(xtr)
xtr.Close()
rpt.Run()
Dim TextExport1 As New GrapeCity.ActiveReports.Export.Xml.Section.TextExport
TextExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "text/plain"
Response.AddHeader("content-disposition", "attachment; filename=MyExport.txt")
Response.BinaryWrite(m_stream.ToArray())
Response.End()

ShowTo write the code in C#

C# code. Paste INSIDE the Page Load event. Copy Code
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\SectionReport1.rpx");
rpt.LoadLayout(xtr);
xtr.Close();
rpt.Run();
GrapeCity.ActiveReports.Export.Xml.Section.TextExport textExport1 = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport (); 
textExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "text/plain";
Response.AddHeader("content-disposition", "attachment; filename=MyExport.txt");
Response.BinaryWrite(m_stream.ToArray());
Response.End();

ShowTo run the project

Press F5 to run the project.

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