Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

INTRODUCTION

This step-by-step article describes how to create a sample Microsoft ASP.NET Web application that uses the Microsoft SQL Server 2000 Reporting Services SOAP APIs and the Microsoft SQL Server 2005 Reporting Services SOAP APIs to perform the following:

  • Render a report that is deployed on a report server to a supported file format, such as the .pdf file format.

  • Open the rendered report on a Web page without saving the file that corresponds to the rendered report on your computer.

Note To render the report to the requested file format by using the ASP.NET Web application, the program that supports the file format must be installed on your computer. For example, to view a report that is rendered to the .pdf file format, Adobe Acrobat Reader must be installed on your computer.

More Information

You can generate a report by using Reporting Services, and you can view the report by using Report Manager. Report Manager is included with Reporting Services. By using Report Manager, you can render your report to different file formats that are supported by Reporting Services. To render a report to a specific file format, follow these steps:

  1. Start Report Manager.

  2. Locate your report in Report Manager, and then click the report to preview your report.

  3. In the Select a format list, click the file format that you want to use to render your report, and then click
    Export.

After you click Export in Report Manager, the
File Download dialog box opens. The File Download dialog box provides an option to save the rendered report on your computer. Even if you open the report without saving the report, a file that corresponds to the rendered report is created on your computer.


If you want to render a report to the requested file format without creating the file that corresponds to the rendered report on your computer, you can use the Render method in the Reporting Services SOAP APIs. For more information about the Render method for SQL Server 2000 Reporting Services, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/aa225827(SQL.80).aspx For more information about the Render method for SQL Server 2005 Reporting Services, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.reportexecutionservice.render.aspxTo create a sample ASP.NET Web application to render a report that is deployed on a report server to the requested file format and to open the rendered report on a Web page by using the Reporting Services SOAP APIs, follow these steps.

Note This sample application renders the Company Sales sample report to the .pdf file format. Therefore, you must make sure that the Company Sales sample report is deployed on your report server in the SampleReports folder. You must also make sure that a program such as Adobe Acrobat Reader is installed on your computer before you run this application.

Use Microsoft Visual Studio .NET 2003 to render the Company Sales sample report that is included in SQL Server 2000 Reporting Services or SQL Server 2005 Reporting Services

  1. Start Microsoft Visual Studio .NET 2003.

  2. On the File menu, click
    New, and then click Project.

  3. In the New Project dialog box, under
    Project Types, click Visual C# Projects.

  4. In the New Project dialog box, under
    Templates, click ASP.NET Web Application.

  5. In the Location box, type
    http://ReportServerName/RenderCompanySales, and then click OK to create the project.

  6. Add a Web reference to the ReportService Web service. To do this, follow these steps:

    1. On the Project menu, click Add Web Reference.

    2. In the Add Web Reference dialog box, type
      http://ReportServerName/ReportServer/ReportService.asmx in the URL box, and then click Go.

    3. In the Web reference name box, type
      RSWebReference, and then click Add Reference.

  7. In the left pane, under Toolbox, click
    Web Forms, and then double-click Button to add a button control to the Web form.

  8. Set the properties of the button control by using the following information:

    • (ID):
      RenderTest

    • Text: Render Report in PDF Format

  9. On the View menu, click
    Code.

  10. Add the following code at the top of the code window:

    using RenderCompanySales.RSWebReference;
  11. Add the following method as the event handler of the click event for the RenderTest button in your code:

    private void RenderTest_Click(object sender, System.EventArgs e)
    {
    RSWebReference.ReportingService rs = new RSWebReference.ReportingService();
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

    Byte[] result;

    string encoding;
    string mimetype;
    ParameterValue[] parametersUsed;
    Warning[] warnings;
    string[] streamids;

    result = rs.Render("/SampleReports/Company Sales","PDF",null,null,null,null,null,out encoding,out mimetype,out parametersUsed,out warnings,out streamids);

    Response.ClearContent();
    Response.AppendHeader("content-length", result.Length.ToString());
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(result);
    Response.Flush();
    Response.Close();
    }
  12. On the Debug menu, click
    Start to run the code.

  13. On the WebForm1 Web page, click
    Render Report in PDF Format.

Use Microsoft Visual Studio 2005 to render the Company Sales sample report that is included in SQL Server 2005 Reporting Services

  1. Start Microsoft Visual Studio 2005.

  2. On the File menu, click
    New, and then click Web Site.

  3. In the New Web Site dialog box, click
    ASP.NET Web Site under Visual Studio installed templates,

  4. Click HTTP in the
    Location list, and then type
    http://ReportServerName/RenderCompanySalesin the box that is next to the Location list

  5. In the Language list, click Visual C#, and then click OK.

  6. Add a Web reference to the ReportService Web service. To do this, follow these steps:

    1. On the Website menu, click Add Web Reference.

    2. In the Add Web Reference dialog box, type
      http://ReportServerName/ReportServer/ReportExecution2005.asmx in the URL box, and then click Go.

    3. In the Web reference name box, type
      RSWebReference, and then click Add Reference.

  7. On the View menu, click
    Designer, and then add a Button control to the Web form.

  8. Set the properties of the Button control by using the following information:

    • (ID):
      RenderTest

    • Text: Render Report in PDF Format

  9. On the View menu, click
    Code.

  10. Add the following line of code at the top of the code window:

    using RSWebReference;
  11. Add the following method as the event handler of the click event for the RenderTest button in your code.

    protected void RenderTest_Click(object sender, EventArgs e)
    {
    ReportExecutionService rs = new ReportExecutionService();
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // Render arguments
    byte[] result = null;
    string reportPath = "/AdventureWorks Sample Reports/Company Sales";
    string format = "PDF";
    string historyID = null;

    string encoding;
    string mimeType;
    string extension;
    Warning[] warnings = 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;

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

    Response.ClearContent();
    Response.AppendHeader("content-length", result.Length.ToString());
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(result);
    Response.Flush();
    Response.Close();

    }
  12. On the Debug menu, click Start Debugging to run the code.

  13. On the Web page that Visual Studio 2005 opens, click
    Render Report in PDF Format.

References

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

842854 Documentation errors in the ReportingService.Render Method topic, the ReportingService.CreateDataDrivenSubscription Method topic, and the ReportingService.CreateReportHistorySnapshot Method topic in Reporting Services Books Online

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×