Asp.Net Core:在客户端浏览器上下载 PDF 格式的 SSRS 报告

Pra*_*ale 7 c# reporting-services asp.net-core

我有一个 SSRS 报告 URL,如果我在浏览器中输入该 URL,则会显示带有打印和保存选项的 SSRS 报告,如下所示:

在此输入图像描述

这在浏览器上运行良好。

我想要的是,页面上有一个按钮.cshtml,因此通过单击该按钮,我需要在客户端浏览器上下载报告。

网址:http://xyz/ReportS/report/UAT/SampleReport_V1?Srno=X123

我尝试过的:

通过设置&rs:Format=PDF并从 Asp.Net Core 应用程序发出 HTTP 请求,但它生成了 PDF,但格式已损坏。

代码:

public void Download_SSRSInPDF()
{
    string URL = "http://xyz/ReportS/report/UAT/SampleReport_V1";
    string Command = "Render";
    string Format = "PDF";
    URL = URL + "?SrNo=X123&rs:Command=" + Command + "&rs:Format=" + Format;
    System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL);

    Req.Credentials = System.Net.CredentialCache.DefaultCredentials;
    Req.Method = "GET";
    string path = @"E:\New folder\Test.pdf";
    System.Net.WebResponse objResponse = Req.GetResponse();
    System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
    System.IO.Stream stream = objResponse.GetResponseStream();
    byte[] buf = new byte[1024];
    int len = stream.Read(buf, 0, 1024);

    while (len > 0)
    {
        fs.Write(buf, 0, len);
        len = stream.Read(buf, 0, 1024);
    }
    stream.Close();
    fs.Close();
}
Run Code Online (Sandbox Code Playgroud)

如何在Asp.Net Core中做到这一点?

编辑:

我有我的报告的 asmx 网址:

http://server-name/ReportServer/reportexecution2005.asmx
Run Code Online (Sandbox Code Playgroud)

但无法继续此操作,有人可以指出我的文档吗?

小智 5

如果您想要一个简单的 URL 来下载 PDF 格式的报告,请不要将参数添加到 Web 门户 URL,而是将它们添加到指向 Web 服务的 URL:

string URL = "http://xyz/reportserver/?/UAT/SampleReport_V1";
string Command = "Render";
string Format = "PDF";
URL = URL + "&SrNo=X123&rs:Command=" + Command + "&rs:Format=" + Format;
Run Code Online (Sandbox Code Playgroud)