Павел, я немного боролся с этим.В конце решил реализовать свой собственный ActionResult и потоковую передачу файла PDF.Это мое действие:
public ActionResults.DownloadFileResult PrintReport()
{
rvDocument = new WebForms.ReportViewer();
rvDocument.ProcessingMode = ProcessingMode.Local;
LocalReport report = rvDocument.LocalReport;
report.ReportPath = Server.MapPath("~/Reports/KingsCourt.rdlc");
string sGuid = Guid.NewGuid.ToString.Replace("-", "");
List<InvoiceRow> rows = new List<InvoiceRow>();
rows.Add(new InvoiceRow { name = "Testing item", value = (decimal)25.85 });
rows.Add(new InvoiceRow { name = "Testing item2", value = (decimal)5.15 });
ReportDataSource source = new ReportDataSource("InvoiceRow", rows);
report.DataSources.Add(source);
rvDocument.LocalReport.Refresh();
string sFileName = Path.Combine("<temp folder>", sGuid + ".PDF");
byte[] StreamBytes = null;
string mimeType = "";
string encoding = "";
string filenameExtension = "";
string[] streamids = null;
Warning[] warnings = null;
StreamBytes = rvDocument.LocalReport.Render("PDF", null, mimeType, encoding, filenameExtension, streamids, warnings);
if ((StreamBytes != null)) {
try {
using (FileStream fs = new FileStream(sFileName, FileMode.CreateNew, FileAccess.Write, FileShare.Write)) {
fs.Write(StreamBytes, 0, StreamBytes.Length);
}
} catch (Exception ex) {
// Log.Logger.WriteException(string.Empty, ex, Log.Logger.LogTypes.Error, this.GetType, "Report001_Load");
}
StreamBytes = null;
}
BPMVC.ActionResults.DownloadFileResult oPdfToStream = new BPMVC.ActionResults.DownloadFileResult();
{
oPdfToStream.FileName = sFileName;
oPdfToStream.ContentType = "application/pdf";
oPdfToStream.DocumentName = "ReportName.pdf";
}
return (oPdfToStream);
}
, и это мой собственный ActionResult
using System.Web.Mvc;
using System.Web;
using System.IO;
namespace ActionResults
{
public class DownloadFileResult : ActionResult
{
#region " Public Properties "
private string _VirtualPath = "";
public string VirtualPath {
get { return (_VirtualPath); }
set { _VirtualPath = value; }
}
private string _FileName = "";
public string FileName {
get { return (_FileName); }
set { _FileName = value; }
}
private string _ContentType = "text/html";
public string ContentType {
get { return (_ContentType); }
set { _ContentType = value; }
}
private string _DocumentName = "";
public string DocumentName {
get { return (_DocumentName); }
set { _DocumentName = value; }
}
#endregion
public override void ExecuteResult(System.Web.Mvc.ControllerContext context)
{
if ((context == null)) {
throw new ArgumentNullException("context");
}
if (string.IsNullOrEmpty(this.FileName) && string.IsNullOrEmpty(this.VirtualPath)) {
throw new ArgumentNullException("FileName is Empty");
}
string filePath = "";
if (string.IsNullOrEmpty(this.VirtualPath)) {
filePath = this.FileName;
} else {
filePath = context.HttpContext.Server.MapPath(this.VirtualPath);
}
if (string.IsNullOrEmpty(this.DocumentName)) {
this.DocumentName = Path.GetFileName(filePath);
}
{
context.HttpContext.Response.Clear();
context.HttpContext.Response.ClearHeaders();
context.HttpContext.Response.ClearContent();
context.HttpContext.Response.ContentType = this.ContentType;
context.HttpContext.Response.AddHeader("Content-Type", this.ContentType);
context.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=\"" + this.DocumentName + "\"");
context.HttpContext.Response.TransmitFile(this.FileName);
context.HttpContext.Response.End();
}
}
}
}