1

我想使用代码中的自定义名称从 SSRS 2016 导出分页报告。如果我使用旧的 2005 控件,我可以做到这一点,但是当我使用新的 URL 访问时,它会提示我(如果我在 Edge 中),但默认为报告的名称,或者在 Chrome 中它只是下载而没有提示。例如,报告名称是 MyTestReport,其中传递了几个参数。我希望能够使用这些参数来设置文件名。

http://localhost/ReportServer/Pages/ReportViewer.aspx?/Finance/MyTestReport&i_entityID=98&i_sy=2016&i_runType=3&i_isPreview=true&rs:Format=PDF

如果可能,该 URL 最好创建一个2016_Preview_Report.pdf的文件名。我已经搜索了 SSRS 文档,但找不到任何关于如何去做的事情。我使用旧的 2005 控件导出为 PDF 的部分代码如下:

IReportServerCredentials irsc = new CustomReportCredentials(userid, password, domain);
var parametersCollection = new List<ReportParameter>();
parametersCollection.Add(new ReportParameter("i_sy", SY.ToString(), false));
parametersCollection.Add(new ReportParameter("i_entityID", LEA.ToString(), false));
parametersCollection.Add(new ReportParameter("i_runType", runtype.ToString(), false));
parametersCollection.Add(new ReportParameter("i_isPreview", isPreview.ToString(), false)); 
ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer();
rv.ProcessingMode = ProcessingMode.Remote;
rv.ServerReport.ReportServerCredentials = irsc;
rv.ServerReport.ReportPath = REPORT_PATH;
rv.ServerReport.ReportServerUrl = new Uri(SSRS_REPORT_SERVER);
rv.ServerReport.SetParameters(parametersCollection);
rv.ServerReport.Refresh();
byte[] streamBytes = null;
string mimeType = "";
string encoding = "";
string filenameExtension = "PDF";
string[] streamids = null;
Warning[] warnings = null;
FileContentResult ReturnFile = null;
filenameExtension = ExportType;
mimeType = "application/pdf";
streamBytes = rv.ServerReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
ReturnFile = File(streamBytes, mimeType, filename + "."+filenameExtension);
return ReturnFile;
4

1 回答 1

1

我是这样做的:

  public ActionResult GetPDFReport(int? id)
{
   string filename = "Generate Filename Here"

   NetworkCredential nwc = new NetworkCredential("username", "password");
   WebClient client = new WebClient();
   client.Credentials = nwc;

   string reportURL = "http://servername//ReportServer?PO&rs:Format=PDF&rs:ClearSession=true&Param1=" + id;
   return File(client.DownloadData(reportURL), "application/pdf", filename);
}
于 2017-02-17T22:40:13.690 回答