XtraReport.ExportToMht(Stream, MhtExportOptions) Method

Exports a report to the specified stream in MHT format using the specified MHT-specific options.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.1.dll

Syntax

public void ExportToMht(
    Stream stream,
    MhtExportOptions options
)

Parameters

Type Name Description
Stream stream

A Stream object to which the created MHT file should be sent.

MhtExportOptions options

A MhtExportOptions object which specifies the MHT export options to be applied when a report is exported.

Once the document export has started, it will run until the resulting document is complete and cannot be interrupted or canceled in the process.

Use this method to export a report to MHT format using the specified MHT export options (like HtmlExportOptionsBase.CharacterSet, HtmlExportOptionsBase.ExportMode and others.) Note that in this instance the current report export options, which are represented by the MhtExportOptions object returned by the ExportOptions.Mht property of a report's XtraReport.ExportOptions, are ignored.

If you want to use the current export options of a report, you should call the overloaded XtraReport.ExportToMht method without the options parameter.

Note

For more information on using the ExportToMht method, and limitations on export to MHT, please refer to the Export to MHT document.

Examples

The following example demonstrates how to export a report to MHT format. To do this, the XtraReport.ExportToMht method should be used. It also demonstrates what specific MhtExportOptions may be used when a report is exported to MHT.

For this example to work, you first need to add a new report (named XtraReport1) to your project, drop some report controls onto it, and then execute the code below (for instance, in the Button.Click event handler of any button on a form). Note also, that if you want the resulting file to be automatically opened in the default program which is used to open *.mht files in your system, you can call the StartProcess method, which is also shown in this example.

using System.Drawing;
using System.Diagnostics;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...

private void ExportToMHT()
{
    // A path to export a report.
    string reportPath = "c:\\Test.mht";

    // Create a report instance.
    XtraReport1 report = new XtraReport1();

    // Get its MHT export options.
    MhtExportOptions mhtOptions = report.ExportOptions.Mht;

    // Set MHT-specific export options.
    mhtOptions.CharacterSet = "UTF-8";
    mhtOptions.TableLayout = false;
    mhtOptions.RemoveSecondarySymbols = false;
    mhtOptions.Title = "Test Title";

    // Set the pages to be exported, and page-by-page options.
    mhtOptions.ExportMode = HtmlExportMode.SingleFilePageByPage;
    mhtOptions.PageRange = "1, 3-5";
    mhtOptions.PageBorderColor = Color.Blue;
    mhtOptions.PageBorderWidth = 3;

    // Export the report to MHT.
    report.ExportToMht(reportPath);

    // Show the result.
    StartProcess(reportPath);
}

// Use this method if you want to automaically open
// the created MHT file in the default program.
public void StartProcess(string path)
{
    Process process = new Process();
    try
    {
        process.StartInfo.FileName = path;
        process.Start();
        process.WaitForInputIdle();
    }
    catch { }
}

See Also