# Async Export

Telerik DataGrid supports export to PDF, Excel and CSV formats. The control allows also asynchronous export which executes on a background thread, thus avoid freezing the main thread.

The async export supports the same features as the standard export, but it provides few additional events and also it requires slightly different output stream management. To use this feature, call the `ExportAsync` method of `RadDataGrid`.

#### **Using the ExportAsync method**

```C#
string projectRootFolderPath = System.IO.Path.GetFullPath("../../../../../../", AppDomain.CurrentDomain.BaseDirectory);
FileStream stream = File.Open(projectRootFolderPath + "\\" + "SampleDocument.xlsx", FileMode.OpenOrCreate);
this.dataGrid.ExportAsync(stream, ExportFormat.Xlsx);     
```

The `Stream` object provided to the `stream` parameter of the method will be automatically closed and disposed when the export operation finishes.

This type of export reports progress. The `AsyncExportProgressChanged` event of `RadDataGrid` is raised each time a row is exported. The event can be used to check the current progress and display additional information to the user, if needed.

#### **Listening for exporting progress changed**

```C#
private void RadDataGrid_AsyncExportProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
	int progress = e.ProgressPercentage;
}
```

The `AsyncExportCompleted` event of `RadDataGrid` is raised when the export finishes. The event arguments contain information about the export state (was it cancelled and is there an error).

#### **Checking the export for errors**

```C#
private void dataGrid_AsyncExportCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
	bool cancelled = e.Cancelled;
	Exception? error = e.Error;
}
```

## See Also

* [Getting Started](https://www.telerik.com/winui/documentation/controls/raddatagrid/gettingstarted)
* [Modifying Exported Data](https://www.telerik.com/winui/documentation/controls/raddatagrid/export/modifying-exported-data)
* [Export to Xls and Xlsx](https://www.telerik.com/winui/documentation/controls/raddatagrid/export/xlsx)
* [Export to PDF](https://www.telerik.com/winui/documentation/controls/raddatagrid/export/pdf)
* [Export to CSV](https://www.telerik.com/winui/documentation/controls/raddatagrid/export/csv)
