Dear Developers,
I am creating an application, in that i have to download jquery datatable as csv file.
Now am downloading as pdf file using the below code on GenericReportController.cs
C# Code
public FileResult ExportCsv(string viewdataName, string fileName)
{
var data = "";
data = TempData[viewdataName].ToString();
TempData[viewdataName] = data;
var dt = (DataTable)JsonConvert.DeserializeObject(data, (typeof(DataTable)));
if (dt.Rows.Count > 0)
{
dt.TableName = fileName.Replace('/', '_');
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dt);
using (MemoryStream stream = new MemoryStream())
{
wb.SaveAs(stream);
return File(stream.ToArray(), "application/octet-stream", fileName + ".csv");
}
}
}
else
return null;
}
How can i download to csv file, kindly suggest me to i am done this task.
Regards
Paul.S