【发布时间】:2015-12-12 11:42:43
【问题描述】:
虽然我可以在调试模式下创建 rdlc 报告,但遇到错误“拒绝访问路径 'C:\xxx.xlsx'。” 在网上查找解决方法后,我看到很多解决方案建议为 IIS 用户授予 C 驱动器权限。但是,授予整个驱动器仅用于呈现报告的权限似乎并不明智。那么,如何更改此渲染位置,即 C:\inetpub\MyApplication?另一方面,我认为报告方面不需要设置,即ReportViewer.ProcessingMode = ProcessingMode.Local; 或更改 rdlc 属性“构建操作”、“复制输出目录”?
注意:我不希望报告在客户端机器上呈现,因为其中一些无权在 C:\ 下写入任何位置,我认为在 IIS 位置生成报告要好得多.不是吗?
那么,在这种情况下,最好的解决方案是什么?
更新:我怎样才能修改这个方法,使它只读取流作为 excel 而无需编写它?
public static void StreamToProcess(Stream readStream)
{
var writeStream = new FileStream(String.Format("{0}\\{1}.{2}", Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), "MyFile", "xlsx"), FileMode.Create, FileAccess.Write);
const int length = 16384;
var buffer = new Byte[length];
var bytesRead = readStream.Read(buffer, 0, length);
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = readStream.Read(buffer, 0, length);
}
readStream.Close();
writeStream.Close();
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + "\\" + "file" + "." + "xlsx");
}
【问题讨论】:
-
为什么要渲染到文件?只需从 MemoryStream 返回一个 FileStreamResult 并让浏览器处理它。
-
你能举个例子吗?
标签: c# asp.net-mvc iis rdlc microsoft-reporting