Export (0) Print
Expand All

Using the ExportToHttpResponse() Method with the ExportOptions Class

Visual Studio 2005

To use the ExportToHttpResponse() method with the ExportOptions parameter, you must complete 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 ExportOptions 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. Within the exportByType_Click() event method, 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)
    {
    }
  5. 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
    {
    }
  6. Within the If block, set the Text property of the message Label control to the FORMAT_NOT_SUPPORTED constant of the MessageConstants class.
    Note   The If condition is satisfied when the NoFormat value from the DropDownList is selected.
    [Visual Basic]
    message.Text = MessageConstants.FORMAT_NOT_SUPPORTED
    [C#]
    message.Text = MessageConstants.FORMAT_NOT_SUPPORTED;
  7. Within the Else block, call the ExportToHttpResponse() method of the hierarchicalGroupingReport instance. Pass in the selected ExportFormatType, 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(exportTypesList.SelectedIndex, Response, True, "ExportedReport")
    [C#]
    hierarchicalGroupingReport.ExportToHttpResponse((ExportFormatType)exportTypesList.SelectedIndex, Response, True, "ExportedReport");
  8. 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;
  9. 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.

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

See Also

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

Show:
© 2015 Microsoft