Export (0) Print
Expand All

Using the ExportToHttpResponse() Method with the ExportFormatType Enumeration

Visual Studio 2005

To use the ExportToHttpResponse() method with the ExportFormatType parameter, you must complete the procedure Adding Controls to the Web or Windows Form for a Web Site. You do not need the ExportSetup(), ExportSelection(), and ExportCompletion() method. The required code is placed in the exportByType click event method.

To use the ExportToHttpResponse() method with the ExportFormatType parameter

  1. Open the Web Form.
  2. From the View menu, click Designer.
  3. Double-click the exportByType Button control.

    The exportByType_Click() event method is created, and you are taken to the Code view.

  4. At the top of the class, add an ExportOptions class declaration.
    [Visual Basic]
    Private myExportOptions As ExportOptions
    [C#]
    private ExportOptions exportOptions;
  5. Within the exportByType_Click() event method, instantiate the ExportOptions instance.
    [Visual Basic]
    myExportOptions = New ExportOptions()
    [C#]
    exportOptions = new ExportOptions();
  6. Create a try/catch block with the Exception class that is referenced as a variable named "ex."
    [Visual Basic]
    Try
    
    Catch ex As Exception
    
    End Try
    [C#]
    try
    {
    }
    catch (Exception ex)
    {
    }
  7. Within the try block, create a conditional block to test if the selected item from the exportTypesList is equal to ExportFormatType.NoFormat.
    [Visual Basic]
    If (exportTypesList.SelectedIndex = ExportFormatType.NoFormat) Then
    
    Else
    
    End If
    [C#]
    if ((ExportFormatType)exportTypesList.SelectedIndex == ExportFormatType.NoFormat)
    {
    }
    else
    {
    }
  8. Within the If block, set the Text property of the message Label control to the FORMAT_NOT_SUPPORTED constant of the MessageConstants class.
    Note   You created the MessageConstants class for this tutorial in Additional Setup Requirements of Project Setup.
    [Visual Basic]
    message.Text = MessageConstants.FORMAT_NOT_SUPPORTED
    [C#]
    message.Text = MessageConstants.FORMAT_NOT_SUPPORTED;
  9. Within the Else block, assign the selected ExportFormatType from the exportTypesList to the ExportFormatType property of the ExportOptions instance.
    [Visual Basic]
    myExportOptions.ExportFormatType = exportTypesList.SelectedIndex
    [C#]
    exportOptions.ExportFormatType = (ExportFormatType)exportTypesList.SelectedIndex;
  10. Within the Else block, call the ExportToHttpResponse() method of the hierarchicalGroupingReport instance. Pass in the ExportOptions instance, the ASP.NET Response object, a True Boolean value, and a file name string as the method parameters..
    Note   The file name string for the attachment does not need an extension because the extension is automatically added to the exported file.
    [Visual Basic]
    hierarchicalGroupingReport.ExportToHttpResponse(myExportOptions, Response, True, "ExportedReport")
    [C#]
    hierarchicalGroupingReport.ExportToHttpResponse(exportOptions, Response, True, "ExportedReport");
  11. Within the catch block, set the Text property of the message Label control to the FAILURE constant of the MessagesConstants class, and then append to it the Message property of the Exception parameter.
    [Visual Basic]
    message.Text = MessageConstants.FAILURE & ex.Message
    [C#]
    message.Text = MessageConstants.FAILURE + ex.Message;
  12. Outside the try/catch block, set the Visible property of the message Label control to "True."
    [Visual Basic]
    message.Visible = True
    [C#]
    message.Visible = true;

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

If you want to use the ExportToHttpResponse() method with the ExportOptions class, see Using the ExportToHttpResponse() Method with the ExportOptions Class.

To use the other enhanced API methods, click the appropriate link to jump to that section:

See Also

Using the ExportToHttpResponse() Method with the ExportOptions Class | Addendum: Enhancements to the Exporting Code | Tutorials: Exporting to Multiple Formats | Tutorials and Sample Code

Show:
© 2015 Microsoft