Creating Methods That Configure Multiple Export Formats
In this section, you create the private helper methods that configure the multiple export formats. All of these method are used similarly, except for ConfigureExportToHtml32() and ConfigureExportToHtml40(), which offer different ways to export to the HTML format.
- ConfigureExportToRpt()
- ConfigureExportToRtf()
- ConfigureExportToDoc()
- ConfigureExportToXls()
- ConfigureExportToPdf()
- ConfigureExportToHtml32()
- ConfigureExportToHtml40()
To create the ConfigureExportToRpt() helper method
Open the Web or Windows Form.
From the View menu, click Code.
At the bottom of the class, create a private helper method named ConfigureExportToRpt() with no return value.
``` vb
Public Sub ConfigureExportToRpt()
End Sub
```
``` csharp
private void ConfigureExportToRpt()
{
}
```
Within the method, set the ExportFormatType property of the ExportOptions instance to the ExportFormatType enum selection CrystalReport.
myExportOptions.ExportFormatType = ExportFormatType.CrystalReport
exportOptions.ExportFormatType = ExportFormatType.CrystalReport;
Set the DiskFileName property of the DiskFileDestinationOptions instance to the exportPath string, and then follow it with the name of a document that has an .rpt file extension.
myDiskFileDestinationOptions.DiskFileName = exportPath & "Report.rpt"
diskFileDestinationOptions.DiskFileName = exportPath + "Report.rpt";
Finally, set the ExportDestinationOptions property of the ExportOptions instance to the DiskFileDestinationOptions instance that you have configured in the previous step.
myExportOptions.ExportDestinationOptions = myDiskFileDestinationOptions
exportOptions.ExportDestinationOptions = diskFileDestinationOptions;
To create the ConfigureExportToRtf helper method
Open the Web or Windows Form.
From the View menu, click Code.
At the bottom of the class, create a private helper method named ConfigureExportToRtf() with no return value.
``` vb
Public Sub ConfigureExportToRtf()
End Sub
```
``` csharp
private void
ConfigureExportToRtf()
{
}
```
Within the method, set the ExportFormatType property of the ExportOptions instance to the ExportFormatType enum selection RichText.
myExportOptions.ExportFormatType = ExportFormatType.RichText
exportOptions.ExportFormatType = ExportFormatType.RichText;
Set the DiskFileName property of the DiskFileDestinationOptions instance to the exportPath string, and then follow it with the name of a document that has an .rtf file extension.
myDiskFileDestinationOptions.DiskFileName = exportPath & "RichTextFormat.rtf"
diskFileDestinationOptions.DiskFileName = exportPath + "RichTextFormat.rtf";
Finally, set the ExportDestinationOptions property of the ExportOptions instance to the DiskFileDestinationOptions instance that you have configured in the previous step.
myExportOptions.ExportDestinationOptions = myDiskFileDestinationOptions
exportOptions.ExportDestinationOptions = diskFileDestinationOptions;
To create the ConfigureExportToDoc helper method
Open the Web or Windows Form.
From the View menu, click Code.
At the bottom of the class, create a private helper method named ConfigureExportToDoc() with no return value.
``` vb
Public Sub ConfigureExportToDoc()
End Sub
```
``` csharp
private void
ConfigureExportToDoc()
{
}
```
Within the method, set the ExportFormatType property of the ExportOptions instance to the ExportFormatType enum selection WordForWindows.
myExportOptions.ExportFormatType = ExportFormatType.WordForWindows
exportOptions.ExportFormatType = ExportFormatType.WordForWindows;
Set the DiskFileName property of the DiskFileDestinationOptions instance to the exportPath string, and then follow it with the name of a document that has a .doc file extension.
myDiskFileDestinationOptions.DiskFileName = exportPath & "Word.doc"
diskFileDestinationOptions.DiskFileName = exportPath + "Word.doc";
Finally, set the ExportDestinationOptions property of the ExportOptions instance to the DiskFileDestinationOptions instance that you have configured in the previous step.
myExportOptions.ExportDestinationOptions = myDiskFileDestinationOptions
exportOptions.ExportDestinationOptions = diskFileDestinationOptions;
To create the ConfigureExportToXls helper method
Open the Web or Windows Form.
From the View menu, click Code.
At the bottom of the class, create a private helper method named ConfigureExportToXls() with no return value.
``` vb
Public Sub ConfigureExportToXls()
End Sub
```
``` csharp
private void
ConfigureExportToXls()
{
}
```
Within the method, set the ExportFormatType property of the ExportOptions instance to the ExportFormatType enum selection Excel.
myExportOptions.ExportFormatType = ExportFormatType.Excel
exportOptions.ExportFormatType = ExportFormatType.Excel;
Set the DiskFileName property of the DiskFileDestinationOptions instance to the exportPath string, and then follow it with the name of a document that has an .xls file extension.
myDiskFileDestinationOptions.DiskFileName = exportPath & "Excel.xls"
diskFileDestinationOptions.DiskFileName = exportPath + "Excel.xls";
Finally, set the ExportDestinationOptions property of the ExportOptions instance to the DiskFileDestinationOptions instance that you have configured in the previous step.
myExportOptions.ExportDestinationOptions = myDiskFileDestinationOptions
exportOptions.ExportDestinationOptions = diskFileDestinationOptions;
To create the ConfigureExportToPdf helper method
Open the Web or Windows Form.
From the View menu, click Code.
At the bottom of the class, create a private helper method named ConfigureExportToPdf() with no return value.
``` vb
Public Sub ConfigureExportToPdf()
End Sub
```
``` csharp
private void
ConfigureExportToPdf()
{
}
```
Within the method, set the ExportFormatType property of the ExportOptions instance to the ExportFormatType enum selection PortableDocFormat.
myExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
Set the DiskFileName property of the DiskFileDestinationOptions instance to the exportPath string, and then follow it with the name of a document that has a .pdf file extension.
myDiskFileDestinationOptions.DiskFileName = exportPath & "PortableDoc.pdf"
diskFileDestinationOptions.DiskFileName = exportPath + "PortableDoc.pdf";
Finally, set the ExportDestinationOptions property of the ExportOptions instance to the DiskFileDestinationOptions instance that you have configured in the previous step.
myExportOptions.ExportDestinationOptions = myDiskFileDestinationOptions
exportOptions.ExportDestinationOptions = diskFileDestinationOptions;
To create the ConfigureExportToHtml32 helper method
Open the Web or Windows Form.
From the View menu, click Code.
At the bottom of the class, create a private helper method named ConfigureExportToHtml32() with no return value.
``` vb
Public Sub ConfigureExportToHtml32()
End Sub
```
``` csharp
private void
ConfigureExportToHtml32()
{
}
```
Within the method, set the ExportFormatType property of the ExportOptions instance to the ExportFormatType enum selection HTML32.
myExportOptions.ExportFormatType = ExportFormatType.HTML32
exportOptions.ExportFormatType = ExportFormatType.HTML32;
Declare and instantiate the HTMLFormatOptions class with the variable name "html32FormatOptions."
Dim html32FormatOptions As HTMLFormatOptions = New HTMLFormatOptions()
HTMLFormatOptions html32FormatOptions = new HTMLFormatOptions();
Set the HTMLBaseFolderName property of the html32FormatOptions instance to the exportPath string, and the name "Html32Folder."
html32FormatOptions.HTMLBaseFolderName = exportPath & "Html32Folder"
html32FormatOptions.HTMLBaseFolderName = exportPath + "Html32Folder";
Set the HTMLFileName property of the html32FormatOptions instance to the name "html32.html."
html32FormatOptions.HTMLFileName = "html32.html"
html32FormatOptions.HTMLFileName = "html32.html";
Set the HTMLEnableSeparatedPage property of the html32FormatOptions instance to be "False."
html32FormatOptions.HTMLEnableSeparatedPages = False
html32FormatOptions.HTMLEnableSeparatedPages = false;
Set the HTMLHasPageNavigator property of the html32FormatOptions instance to be "False."
html32FormatOptions.HTMLHasPageNavigator = False
html32FormatOptions.HTMLHasPageNavigator = false;
Finally, assign the html32FormatOptions instance to the FormatOptions property of the ExportOptions instance.
myExportOptions.ExportFormatOptions = html32FormatOptions
exportOptions.ExportFormatOptions = html32FormatOptions;
To create the ConfigureExportToHtml40 helper method
Open the Web or Windows Form.
From the View menu, click Code.
At the bottom of the class, create a private helper method named ConfigureExportToHtml40() with no return value.
``` vb
Public Sub ConfigureExportToHtml40()
End Sub
```
``` csharp
private void
ConfigureExportToHtml40()
{
}
```
Within the method, set the ExportFormatType property of the ExportOptions instance to the ExportFormatType enum selection HTML40.
myExportOptions.ExportFormatType = ExportFormatType.HTML40
exportOptions.ExportFormatType = ExportFormatType.HTML40;
Declare and instantiate the HTMLFormatOptions class with the variable name "html40FormatOptions."
Dim html40FormatOptions As HTMLFormatOptions = New HTMLFormatOptions()
HTMLFormatOptions html40FormatOptions = new HTMLFormatOptions();
Set the HTMLBaseFolderName property of the html40FormatOptions instance to the exportPath string and the name "Html40Folder."
html40FormatOptions.HTMLBaseFolderName = exportPath & "Html40Folder"
html40FormatOptions.HTMLBaseFolderName = exportPath + "Html40Folder";
Set the HTMLFileName property of the html40FormatOptions instance to the name "html40.html."
html40FormatOptions.HTMLFileName = "html40.html"
html40FormatOptions.HTMLFileName = "html40.html";
Set the HTMLEnableSeparatedPage property of the html40FormatOptions instance to "True."
html40FormatOptions.HTMLEnableSeparatedPages = True
html40FormatOptions.HTMLEnableSeparatedPages = true;
Set the HTMLHasPageNavigator property of the html40FormatOptions instance to be "True."
html40FormatOptions.HTMLHasPageNavigator = True
html40FormatOptions.HTMLHasPageNavigator = true;
Set the FirstPageNumber property of the html40FormatOptions instance to 1.
html40FormatOptions.FirstPageNumber = 1
html40FormatOptions.FirstPageNumber = 1;
Set the LastPageNumber property of the html40FormatOptions instance 3.
html40FormatOptions.LastPageNumber = 3
html40FormatOptions.LastPageNumber = 3;
Finally, assign the html40FormatOptions instance to the FormatOptions property of the ExportOptions instance.
myExportOptions.FormatOptions = html40FormatOptions
exportOptions.FormatOptions = html40FormatOptions;
You have created the private helper methods that configure the multiple export formats.