如何在asp.net c#中将Telerik数据导出到.csv文件中

时间:2011-09-16 06:51:01

标签: asp.net c#-4.0 telerik-reporting

我已经在asp.net中开发了一个小应用程序,我已经根据Telerik报告来获取数据,在aspx中我使用了telerik报告查看器,当我运行并单击按钮时它会生成“ .pdf “文件很好。但是,我想生成.csv文件

这是我的代码(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();
    }

请帮助我,我已经尝试在RenderingResult中替换.csv替换.pdf它显示错误是否还有其他解决方案?请

1 个答案:

答案 0 :(得分:0)

尝试改变:

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