如何在SSRS 2016中自定义报告的名称以进行输出?

时间:2016-08-11 16:34:36

标签: reporting-services ssrs-2016

我想使用代码中的自定义名称从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;

1 个答案:

答案 0 :(得分: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);
}