【发布时间】:2018-08-20 07:53:43
【问题描述】:
我正在使用以下代码来创建和下载 Telerik 报告。
var reportName = "../api/Templates/Invoice.trdp";
var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
var reportSource = new Telerik.Reporting.UriReportSource()
{
Uri = reportName
};
reportSource.Parameters.Add("ID", 3);
reportSource.Parameters.Add("Username", "demouser");
var deviceInfo = new System.Collections.Hashtable()
{
{"DocumentTitle", "Annual Report" }
};
var result = reportProcessor.RenderReport("PDF", reportSource, deviceInfo);
if (!result.HasErrors)
{
System.IO.File.WriteAllBytes(System.IO.Path.ChangeExtension(reportName, "pdf"), result.DocumentBytes);
}
}
一旦我将它托管在服务器中,它就会在服务器端创建文件。如何在不在服务器中创建任何文件的情况下将其下载到客户端计算机中。
【问题讨论】:
-
在服务器端生成文件然后给客户端一个文件的链接是没有错的,只要在文件下载后的某个时间点有删除报告的任务.确保生成文件的目录是临时目录,并且文件名不能被猜到。
-
@Neil,是的。你是对的。目前我正在使用这种方法。但是我只想知道天气可以直接下载到客户端吗。
-
最后一行:
result.DocumentBytes是Stream或byte[],无论哪种方式,都可以转换为IFileResult并直接传递给客户端。 -
@Neil 我使用与您建议的类似方式完成了任务。谢谢。
标签: c# reporting telerik-reporting