Search code examples
asp.netc#-4.0telerik-reporting

How to export Telerik Data into .csv file in asp.net c#


I have develop a small application in asp.net and i have genarate Telerik reports to get data,in aspx i took the telerik report viewer and when i run and click the button it genarate ".pdf" file it's fine.But,i want generate the .csv file

Here is My code(c#)

    protected void btndayreport_Click(object sender, EventArgs e)
     {
        // Clients client = new Clients();
        ScheduleReport dayreport = new ScheduleReport();
        dayreport.date = Convert.ToDateTime(System.DateTime.Now.ToShortDateString());
        ReportProcessor reportProcessor = new ReportProcessor();
        RenderingResult result = reportProcessor.RenderReport("PDF", dayreport, null);
        string reports = System.DateTime.Now + "DayReport.pdf";
        FileStream fs = new FileStream(Server.MapPath("/Reports/") + reports, FileMode.Create);
        // FileStream fs = new FileStream("BeforeMergeReport.pdf", FileMode.Create);
        fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
        fs.Flush();
        fs.Close();
        // ReadPdfFile();
    }

please help me ,i have try replace .csv insted of .pdf in RenderingResult it showing error is there any other solution? please


Solution

  • Try to change:

    1. reportProcessor.RenderReport("PDF", dayreport, null) to reportProcessor.RenderReport("CSV", dayreport, null)
    2. System.DateTime.Now + "DayReport.pdf" to System.DateTime.Now + "DayReport.csv"