xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xtrareport-dot-exporttortfasync-x28-system-dot-string-devexpress-dot-xtraprinting-dot-rtfexportoptions-system-dot-threading-dot-cancellationtoken-x29.md
Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.
Asynchronously exports a report to the specified file in RTF format.
Namespace : DevExpress.XtraReports.UI
Assembly : DevExpress.XtraReports.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
public Task ExportToRtfAsync(
string path,
RtfExportOptions options = null,
CancellationToken token = default(CancellationToken)
)
Public Function ExportToRtfAsync(
path As String,
options As RtfExportOptions = Nothing,
token As CancellationToken = Nothing
) As Task
| Name | Type | Description |
|---|---|---|
| path | String |
The path to the exported PDF file.
|
| Name | Type | Default | Description |
|---|---|---|---|
| options | RtfExportOptions | null |
The RTF export options. You can omit this parameter to use the current report export options.
| | token | CancellationToken | null |
A cancellation token that the task observes.
|
| Type | Description |
|---|---|
| Task |
A task that exports the report.
|
This method is equivalent to the ExportToRtf(String, RtfExportOptions) method but does not lock other actions performed concurrently. For instance, the user interface remains operational while the application exports a report.
Call ExportToRtfAsync from an async method. Prefix the call with the await operator, as shown in the code sample below.
The optional CancellationToken parameter provides a way to send the cancellation signal to the task. The task monitors the token and stops when it receives the signal. Create a CancellationTokenSource class instance and pass its Token property to the ExportToRtfAsync method call. Call the CancellationTokenSource.Cancel method to stop the task.
The code sample below exports a report to RTF asynchronously. A CancellationTokenSource class instance is used to allow users to interrupt the report export if it takes too long.
using DevExpress.XtraReports.UI;
using System;
using System.Threading;
// Use cancellationTokenSource to allow users to stop the document creation process.
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
async public void ExportReportToRtfFileAsync()
{
// Create a simple report.
XtraReport report = new XtraReport()
{
Name = "SimpleReport",
Bands = {
new DetailBand() {
Controls = {
new XRLabel() {
Text = "Simple Report"
}
}
}
}
};
// Export the report. The export file is added to the user's Downloads folder.
await report.ExportToRtfAsync(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\" + report.Name + ".rtf",
null,
cancellationTokenSource.Token);
}
Imports System
Imports System.Windows.Forms
Imports System.Threading
Imports DevExpress.XtraReports.UI
' ...
' Use the cancellationTokenSource to allow users to stop the report export.
Private cancellationTokenSource As New CancellationTokenSource()
' ...
' The cancelButton_Click event handler uses cancellationTokenSource to stop the report export.
Private Sub cancelButton_Click(ByVal sender As Object, ByVal e As EventArgs)
cancellationTokenSource.Cancel()
End Sub
' ...
Public Async Sub ExportReportToRtfFileAsync()
' Create a simple report.
Dim report As New XtraReport() With {
.Name = "SimpleReport", .Bands = {
New DetailBand() With {
.Controls = {
New XRLabel() With {.Text = "Simple Report"}
}
}
}
}
' Export the report. The export file is placed to the user's Downloads folder.
Await report.ExportToRtfAsync(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) & "\Downloads\" & report.Name & ".rtf", Nothing, cancellationTokenSource.Token)
End Sub
See Also