'I want to Export the data/content of DataGrid to Pdf & csv file in UWP application
There is no any such specific answer for UWP implementation that will give me the correct solution.
I have a datagrid which will have data from it's item source.
Solution tried:- Export To PDF in UWP DataGrid (SfDataGrid) - Syncfusion. Tried this as well:- Export DataGridView Data To PDF In C# - C# corner solution.
I just want to save the datagridview and its content to pdf or csv on my local memory.
Is there a direct and simple way for this implementation without the need/help of 3rd party controls?
Solution 1:[1]
I want to Export the data/content of DataGrid to Pdf & csv file in UWP application
I think you have not to save the datagridview to csv, you could save the datasoure collection to csv indirectly. please refer to csv document writing a csv file.
var csvfile = await ApplicationData.Current.LocalFolder.CreateFileAsync("test.csv", CreationCollisionOption.OpenIfExists);
var records = new List<Foo>
{
new Foo { Id = 1, Name = "one" },
new Foo { Id = 2, Name = "two" },
};
using (var writer = new StreamWriter(csvfile.Path))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(records);
}
Please note the stream writer path should be UWP local folder path that has full access permission.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
