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);
}
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
andElementExported
events ofRadDataGrid
. Read more in the Modifying Exported Data article.