Click here to Skip to main content
14,699,491 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've been trying to convert a SSRS Report to PDF and save to my local drive using the Reporting Web Services. Though I'm able to generate the corresponding pdf file but the contents of the file are missing. I've checked that the report I'm trying to convert is not an empty one. Only the header section is present there within the generated pdf files. Below is the code I'm using:


protected void GeneratePDFFromReport(object sender, EventArgs e)
    {
        RS2005.ReportingService2005 rs;
        RE2005.ReportExecutionService rsExec;

        // Create a new proxy to the web service
        rs = new RS2005.ReportingService2005();
        rsExec = new RE2005.ReportExecutionService();

        // Authenticate to the Web service using Windows credentials
        rs.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
        rsExec.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
        //rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;

        rs.Url = "http://servername/reportserver/reportservice2005.asmx";
        rsExec.Url = "http://servername/reportserver/reportexecution2005.asmx";

        string historyID = null;
        string deviceInfo = null;
        string format = "PDF";
        Byte[] results;
        string encoding = String.Empty;
        string mimeType = "application/pdf";
        string extension = String.Empty;
        RE2005.Warning[] warnings = null;
        string[] streamIDs = null;

        // Path of the Report - XLS, PDF etc.
        string fileName = @"C:\Report\MemberReport.pdf";
        // Name of the report - Please note this is not the RDL file.
        string _reportName = @"/ReportFolder/ReportName";
        string _historyID = null;
        bool _forRendering = false;
        RS2005.ParameterValue[] _values = null;
        RS2005.DataSourceCredentials[] _credentials = null;
        RS2005.ReportParameter[] _parameters = null;

        try
        {
            _parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);
            RE2005.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID);

            results = rsExec.Render(format, deviceInfo,
                      out extension, out encoding,
                      out mimeType, out warnings, out streamIDs);

            try
            {
                FileStream stream = File.Create(fileName, results.Length);
                stream.Write(results, 0, results.Length);
                stream.Close();
            }
            catch { }

            results = null;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }


Any help would highly be appreciated. Thanks.
Posted
Updated 4-May-20 0:07am

I saw that you have posted your question @ bottom of that article[^]. Wait for some time.

Meantime, look for some other places for solutions, check these articles
Create data driven PDF on the fly by using SQL server reporting service (SSRS)[^]
Create PDF via SQL Server Reporting Service or Report Viewer Control[^]
   
You forgot to add the parameters to your report.

Add rsExec.SetExecutionParameters(_parameters, string.empty); after the LoadReport.

_parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);

RE2005.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID);

rsExec.SetExecutionParameters(_parameters, string.empty);
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900