Using the ExportToStream() Method
In this section, you learn how to use the ExportToStream() method to export the report to the input/output stream as a sequence of bytes. Then, you learn how to write the sequence of bytes to a file of your specified format.
When you export the report to the HTML formats, the images are not exported. It is recommended to use the ExportToHttpResponse() methods when you want to export to the HTML formats.
Prerequisites:
You must create a project that is based on the instructions in Setting Up a Project for the ExportToStream() Method.
Or, you must create a project that is based on the instructions in Creating Methods for the New Exporting Formats.
Then, you need to modify the project as shown in Preparing the Project for the ExportToStream() Method.
To modify the case statements in the ExportSelection() method
- Within the ExportSelection() method, declare a string variable and instantiate the variable to an empty string.
``` vb
Dim myFileName As String = ""
```
``` csharp
string fileName = "";
```
Within the ExportFormatType.CrystalReport case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .rpt file extension.
myFileName = exportPath & "Report.rpt"
myFileName = exportPath + "Report.rpt";
Within the ExportFormatType.RichText case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .rtf file extension.
myFileName = exportPath & "RichTextFormat.rtf"
myFileName = exportPath + "RichTextFormat.rtf";
Within the ExportFormatType.WordForWindows case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .doc file extension.
myFileName = exportPath & "Word.doc"
fileName = exportPath + "Word.doc";
Within the ExportFormatType.Excel case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .xls file extension.
myFileName = exportPath & "Excel.xls"
fileName = exportPath + "Excel.xls";
Within the ExportFormatType.PortableDocFormat case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .pdf file extension.
myFileName = exportPath & "PortableDoc.pdf"
fileName = exportPath + "PortableDoc.pdf";
Within the ExportFormatType.HTML32 case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .html file extension.
myFileName = exportPath & "HTML32.html"
fileName = exportPath + "HTML32.html";
Within the ExportFormatType.HTML40 case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .html file extension.
myFileName = exportPath & "HTML40.html"
fileName = exportPath + "HTML40.html";
Within the ExportFormatType.ExcelRecord case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .xls file extension.
myFileName = exportPath & "ExcelRecord.xls"
fileName = exportPath + "ExcelRecord.xls";