Export (0) Print
Expand All

Calling the ExportToDisk() Method

Visual Studio 2005

In this section, you learn to call the ExportToDisk() method in each case statement of the ExportSelection() method.

To call the ExportToDisk() method in the ExportSelection() method

  1. Within the ExportSelection() method, declare a string variable and instantiate the variable to an empty string.
    [Visual Basic]
    Dim myFileName As String = ""
    [C#]
    string fileName = "";
  2. Within the ExportFormatType.CrystalReport case statement, do the following:
    1. Set the file name string to the exportPath string, and then follow it with the name of a document that has an .rpt file extension.
      [Visual Basic]
      myFileName = exportPath & "Report.rpt"
      [C#]
      fileName = exportPath + "Report.rpt";
    2. Call the ExportToDisk() method from the hierarchicalGroupingReport instance and pass in ExportFormatType.CrystalReport and the file name string.
      [Visual Basic]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.CrystalReport, myFileName)
      [C#]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.CrystalReport, fileName);
  3. Within the ExportFormatType.RichText case statement, do the following:
    1. Set the file name string to the exportPath string, and then follow it with the name of a document that uses an .rtf file extension.
      [Visual Basic]
      myFileName = exportPath & "RichTextFormat.rtf"
      [C#]
      fileName = exportPath + "RichTextFormat.rtf";
    2. Call the ExportToDisk() method from the hierarchicalGroupingReport instance and pass in ExportFormatType.RichText and the file name string.
      [Visual Basic]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.RichText, myFileName)
      [C#]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.RichText, fileName);
  4. Within the ExportFormatType.WordForWindows case statement, do the following:
    1. Set the file name string to the exportPath string, and then follow it with the name of a document that uses a .doc file extension.
      [Visual Basic]
      myFileName = exportPath & "Word.doc"
      [C#]
      fileName = exportPath + "Word.doc";
    2. Call the ExportToDisk() method from the hierarchicalGroupingReport instance and pass in ExportFormatType.WordForWindows and the file name string.
      [Visual Basic]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.WordForWindows, myFileName)
      [C#]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.WordForWindows, fileName);
  5. Within the ExportFormatType.Excel case statement, do the following:
    1. Set the file name string to the exportPath string, and then follow it with the name of a document that uses an .xls file extension.
      [Visual Basic]
      myFileName = exportPath & "Excel.xls"
      [C#]
      fileName = exportPath + "Excel.xls";
    2. Call the ExportToDisk() method from the hierarchicalGroupingReport instance and pass in ExportFormatType.Excel and the file name string.
      [Visual Basic]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.Excel, myFileName)
      [C#]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.Excel, fileName);
  6. Within the ExportFormatType.PortableDocFormat case statement, do the following:
    1. Set the file name string to the exportPath string, and then follow it with the name of a document that uses a .pdf file extension.
      [Visual Basic]
      myFileName = exportPath & "PortableDoc.pdf"
      [C#]
      fileName = exportPath + "PortableDoc.pdf";
    2. Call the ExportToDisk() method from the hierarchicalGroupingReport instance and pass in ExportFormatType.PortableDocFormat and the file name string.
      [Visual Basic]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.PortableDocFormat, myFileName)
      [C#]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.PortableDocFormat, fileName);
  7. Within the ExportFormatType.HTML32 case statement, do the following:
    1. Set the file name string to the exportPathHTML32 string, and then follow it with the name of a document that uses an .html file extension.
      [Visual Basic]
      myFileName = exportPathHTML32 & "HTML32.html"
      [C#]
      fileName = exportPathHTML32 + "HTML32.html";
    2. Call the ExportToDisk() method from the hierarchicalGroupingReport instance and pass in ExportFormatType.HTML32 and the file name string.
      [Visual Basic]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.HTML32, myFileName)
      [C#]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.HTML32, fileName);
  8. Within the ExportFormatType.HTML40 case statement, do the following:
    1. Set the file name string to the exportPathHTML40 string, and then follow it with the name of a document that uses an .html file extension.
      [Visual Basic]
      myFileName = exportPathHTML40 & "HTML40.html"
      [C#]
      fileName = exportPathHTML40 + "HTML40.html";
    2. Call the ExportToDisk() method from the hierarchicalGroupingReport instance and pass in ExportFormatType.HTML40 and the file name string.
      [Visual Basic]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.HTML40, myFileName)
      [C#]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.HTML40, fileName);
  9. Within the ExportFormatType.ExcelRecord case statement, do the following:
    1. Set the file name string to the exportPath string, and then follow it with the name of a document that uses an .xls file extension.
      [Visual Basic]
      myFileName = exportPath & "ExcelRecord.xls"
      [C#]
      fileName = exportPath + "ExcelRecord.xls";
    2. Call the ExportToDisk() method from the hierarchicalGroupingReport instance and pass in ExportFormatType.ExcelRecord and the file name string.
      [Visual Basic]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.ExcelRecord, myFileName)
      [C#]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.ExcelRecord, fileName);
  10. Within the ExportFormatType.Text case statement, do the following:
    1. Set the file name string to the exportPath string, and then follow it with the name of a document that uses a .txt file extension.
      [Visual Basic]
      myFileName = exportPath & "Text.txt"
      [C#]
      fileName = exportPath + "Text.txt";
    2. Call the ExportToDisk() method from the hierarchicalGroupingReport instance and pass in ExportFormatType.Text and the file name string.
      [Visual Basic]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.Text, myFileName)
      [C#]
      hierarchicalGroupingReport.ExportToDisk(ExportFormatType.Text, fileName);

You are now ready to build and run the project, to export your Crystal report into different formats.

If you want use the other enhanced API methods, click the appropriate link to jump to that section:

See Also

Addendum: Enhancements to the Exporting Code | Tutorials: Exporting to Multiple Formats | Tutorials and Sample Code

Show:
© 2014 Microsoft