Partilhar via


ReportExecutionService.Render method in SharePoint integrated mode

Reporting service provides very convenient way of rendering your reports with the help of Web Service API's. You'll find a whole lot of documents out there in the web. But one thing we often have to search is, what should be the PATH of the report when we use the LoadReport method in order to prepare the report for execution.

The below article beautifully explains the use of Render method in native mode.

https://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx

 But how can we use this against SharePoint integrated mode? That is what we'll be looking today.

First, the report path should be an absolute URL that includes the details of document library where the report is deployed.

For example, I've a web application on the server where I use the URL https://selvar to reach out to the web application.

I've a document library, Shared Documents where I've deployed the report named SimpleSelect

So, the absolute report URL looks like: https://selvar/Shared%20Documents/SimpleSelect.rdl. Browsing this URL will get you to the report.

If you've reports in sites and site collections, just change the above URL accordingly.

Having said that, we've pretty much framed the URL for report that we'll be rendering using the RENDER method.

In order to add the ReportExecution2005.asmx web service reference to the project, the URL will look like: https://selvar/_vti_bin/reportserver/ReportExecution2005.asmx

With the necessary details in hand, the below is the modified version of sample for the Render method in SharePoint integrated mode.

 

class Program

    {

        static void Main(string[] args)

        {

            ReportExecutionService rs = new ReportExecutionService();

        rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

        rs.Url = "https://selvar/_vti_bin/reportserver/ReportExecution2005.asmx";

 

        // Render arguments

        byte[] result = null;

        string reportPath = "https://selvar/Shared%20Documents/SimpleSelect.rdl";

        string format = "PDF";

        string historyID = null;

        string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

        string showHideToggle = null;

        string encoding;

        string mimeType;

        string extension;

        Warning[] warnings = null;

        ParameterValue[] reportHistoryParameters = null;

        string[] streamIDs = null;

       

        ExecutionInfo execInfo = new ExecutionInfo();

        ExecutionHeader execHeader = new ExecutionHeader();

 

        rs.ExecutionHeaderValue = execHeader;

 

        execInfo = rs.LoadReport(reportPath, historyID);

 

        String SessionId = rs.ExecutionHeaderValue.ExecutionID;

 

        Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);

         try

        {

            result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

             execInfo = rs.GetExecutionInfo();

             Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);

         }

        catch (SoapException e)

        {

            Console.WriteLine(e.Detail.OuterXml);

        }

         // Write the contents of the report to an MHTML file.

        try

        {

            FileStream stream = File.Create("D:\\report.pdf", result.Length);

            Console.WriteLine("File created.");

            stream.Write(result, 0, result.Length);

            Console.WriteLine("Result written to the file.");

            stream.Close();

        }

        catch (Exception e)

        {

            Console.WriteLine(e.Message);

        }

     }

     }

 

HTH!

Selva.

[All the posts are AS-IS without any warranty]

Comments

  • Anonymous
    February 03, 2015
    The comment has been removed