Asp.Net Core: Download SSRS reports in PDF format on client browser

廉价感情. 提交于 2019-12-17 21:07:01

问题


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.

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

What I tried:

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

Code:

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

How to do it in Asp.Net Core?

EDIT::

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?


回答1:


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;



回答2:


You're better off doing this using the supported ReportExecution2005.asmx endpoint with something like WCF, instead of trying to use HTTP web request to impersonate a user interaction in a browser.

Once you've got it setup, there are Render methods on the report execution instance that make it really easy to get the report as a PDF.




回答3:


you are converting to pdf with default converter of code. we do not follow this method to convert reports in to pdf. If you wanna ask more option which is lengthy but not tough to do. You can use WKHTMLtopdf method to convert your html in to pdf. it is easy to use. I am not saying that the method you are using is wrong. but we need to use latest technologies. Asp.netcore is working fine with wkhtmltopdf to convert html page in to pdf.



来源:https://stackoverflow.com/questions/58020793/asp-net-core-download-ssrs-reports-in-pdf-format-on-client-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!