mat*_*uma 9 .net c# pdf streaming memorystream
不确定如何说出这个问题...欢迎编辑!无论如何......这里去了.
我目前使用Crystal Reports生成Pdfs并将输出流式传输给用户.我的代码如下所示:
System.IO.MemoryStream stream = new System.IO.MemoryStream();
stream = (System.IO.MemoryStream)this.Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
this.Response.Clear();
this.Response.Buffer = true;
this.Response.ContentType = "application/pdf";
this.Response.BinaryWrite(stream.ToArray());
this.Response.End();
Run Code Online (Sandbox Code Playgroud)
运行此代码后,它将Pdf流式传输到浏览器,打开Acrobat Reader.效果很好!
我的问题是当用户尝试将文件保存为实际文件名时...在这种情况下,它默认为CrystalReportPage.pdf.无论如何我可以设置这个吗?如果是这样,怎么样?
任何帮助,将不胜感激.
Mar*_*ell 17
通常,通过内容处置标题 - 即
Content-Disposition: inline; filename=foo.pdf
Run Code Online (Sandbox Code Playgroud)
所以只需使用Headers.Add或AddHeader,或者其他任何东西,使用:
response.Headers.Add("Content-Disposition","inline; filename = foo.pdf");
(内联是"在浏览器中显示",附件是"另存为文件")
System.IO.MemoryStream stream = new System.IO.MemoryStream();
stream = (System.IO.MemoryStream)this.Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
this.Response.Clear();
this.Response.Buffer = true;
this.Response.ContentType = "application/pdf";
this.Response.AddHeader("Content-Disposition", "attachment; filename=\""+FILENAME+"\"");
this.Response.BinaryWrite(stream.ToArray());
this.Response.End();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8020 次 |
| 最近记录: |