New to Telerik UI for WinUI? Download free 30-day trial

Export to CSV

The export feature allows you to save the data from the DataGrid component to few different formats. This article shows how to save it to csv.

Exporting the Document

The feature works with the Export and ExportAsync methods of RadDataGrid. The methods allow you to provide a stream (usually pointing to a file), a document format and export options objects.

Export DataGrid to CSV format

string projectRootFolderPath = System.IO.Path.GetFullPath("../../../../../../", AppDomain.CurrentDomain.BaseDirectory); 
using (var stream = File.Open(projectRootFolderPath + "\" + "SampleDocument.csv", FileMode.OpenOrCreate)) 
{ 
    this.dataGrid.Export(stream, ExportFormat.Csv); 
} 
To include additional settings for the document, use the DataGridExportOptions class. Read more about the available settings in the Modifying Exported Data article.

Using the DataGridExportOptions

string projectRootFolderPath = System.IO.Path.GetFullPath("../../../../../../", AppDomain.CurrentDomain.BaseDirectory); 
using (var stream = File.Open(projectRootFolderPath + "\" + "SampleDocument.csv", FileMode.OpenOrCreate)) 
{ 
    this.dataGrid.Export(stream, ExportFormat.Csv, new DataGridExportOptions() 
    { 
        ShowColumnHeaders = true, 
    }); 
} 

The exporting process can be customized at runtime using the ElementExporting and ElementExported events of RadDataGrid. Read more in the Modifying Exported Data article.

See Also

In this article
Not finding the help you need?