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

问题描述:

我有一个SSRS报告URL,如果我在浏览器中输入该URL,它将显示带有打印并保存"选项的SSRS报告,例如:

I have one SSRS report URL which if I enter that URL in the browser then it shows the SSRS report with Print and Save option like:

在浏览器上可以正常工作.

Which works fine on the browser.

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

What I want, there is one button on .cshtml page so by clicking on that button I need to download the report on client browser.

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

我尝试过的事情:

通过设置&rs:Format=PDF并从Asp.Net Core Application发出了HTTP请求,但它生成的PDF格式却损坏.

by setting &rs:Format=PDF and made a HTTP Request from Asp.Net Core Application but it generated PDF but in corrupt format.

代码:

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();
}

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

How to do it in Asp.Net Core?

:

我有报告的asmx网址:

I have that asmx url of my report:

http://server-name/ReportServer/reportexecution2005.asmx

但是无法继续进行下去,有人可以将我指向文档吗?

But unable to proceed with this, can someone points me towards documentation?

如果要使用简单的URL以PDF格式下载报告,请不要在Web门户URL中添加参数,而要将其添加到指向以下URL的URL中:网络服务:

If you want a simple URL to download the report in PDF format, don't add parameters to the web portal URL but add them to an URL that points to the web service:

string URL = "http://xyz/reportserver/?/UAT/SampleReport_V1";
string Command = "Render";
string Format = "PDF";
URL = URL + "&SrNo=X123&rs:Command=" + Command + "&rs:Format=" + Format;