ActiveReports 6 Online Help Send comments on this topic.
Custom Web Exporting (Std Edition)
See Also
ActiveReports 6 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Web Walkthroughs (Standard Edition) > Custom Web Exporting (Std Edition)

Glossary Item Box

ActiveReports provides components that allow you to export your reports into several popular formats. The following walkthroughs demonstrate how 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.

To add a report and an export control to the Web project

  1. From the View menu, select Component Designer to go to the design view of the aspx file.
  2. Select the export control you want to use in the Visual Studio toolbox. (See Adding ActiveReports controls for help on adding them to the toolbox.)
  3. Drag the export control onto the aspx design view. (Or you can add references to the export
  4. From the Project menu, select Add New Item.
  5. In the Add New Item window that appears, select the ActiveReports 6 (code-based) File template, rename the report, and click the Add button.
  6. Design your report.

To add code to the Web Form to 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.

PDF

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 NewActiveReport1
rpt.Run()
If Me.PdfExport1 Is Nothing Then
   Me.PdfExport1 = New DataDynamics.ActiveReports.Export.Pdf.PdfExport
End If
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();
NewActiveReport1 rpt = new NewActiveReport1();
rpt.Run();
if (this.pdfExport1 == null)
{
        this.pdfExport1 = new DataDynamics.ActiveReports.Export.Pdf.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();

Excel

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 NewActiveReport1()
rpt.Run()
If Me.XlsExport1 Is Nothing Then
    Me.XlsExport1 = New DataDynamics.ActiveReports.Export.Xls.XlsExport
End If
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();
NewActiveReport1 rpt = new NewActiveReport1();
rpt.Run();
if (this.xlsExport1 == null)
{
        this.xlsExport1 = new DataDynamics.ActiveReports.Export.Xls.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();

TIFF

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 NewActiveReport1()
rpt.Run()
If Me.TiffExport1 Is Nothing Then
    Me.TiffExport1 = New DataDynamics.ActiveReports.Export.Tiff.TiffExport
End If
Me.TiffExport1.CompressionScheme = DataDynamics.ActiveReports.Export.Tiff.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();
NewActiveReport1 rpt = new NewActiveReport1();
rpt.Run();
if (this.tiffExport1 == null)
{ 
        this.tiffExport1 = new DataDynamics.ActiveReports.Export.Tiff.TiffExport(); 
} 
tiffExport1.CompressionScheme = DataDynamics.ActiveReports.Export.Tiff.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();

RTF

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 NewActiveReport1()
rpt.Run()
If Me.RtfExport1 Is Nothing Then
    Me.RtfExport1 = New DataDynamics.ActiveReports.Export.Rtf.RtfExport
End If
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();
NewActiveReport1 rpt = new NewActiveReport1();
rpt.Run();
if (this.rtfExport1 == null) 
{ 
        this.rtfExport1 = new DataDynamics.ActiveReports.Export.Rtf.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();

Plain Text

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 NewActiveReport1()
rpt.Run()
If Me.TextExport1 Is Nothing Then
    Me.TextExport1 = New DataDynamics.ActiveReports.Export.Text.TextExport
End If
TextExport1.Export(rpt.Document, m_stream)
m_stream.Position = 0
Response.ContentType = "text/plain"
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();
NewActiveReport1 rpt = new NewActiveReport1();
rpt.Run();
if (this.textExport1 == null) 
{ 
        this.textExport1 = new DataDynamics.ActiveReports.Export.Text.TextExport(); 
}
textExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "text/plain";
Response.BinaryWrite(m_stream.ToArray());
Response.End();

To view the results in your Web browser, run the project.

See Also