Generate pdf file by using Reporting Service from C#.net

  • Si Thu

    SSC-Addicted

    Points: 435

    Hi,

    I trying to generate pdf file by using the report from Reporting. I found the C# code as follow but I see that the 2005/2008 websvc doesn't have the SessionHeader class as seen in SQL 2000.

    I think, this code is for SQL 2000 and what I

    am I to do in 2008?

    Anyone give me some sample code please.

    Thank you..

    ReportingService.ReportingService rs = new ReportingService.ReportingService();

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

    // Render arguments

    byte[] result = null;

    string format = "PDF";

    string historyID = null;

    string devInfo = null;

    parameters = new ReportingService.ParameterValue[1];

    parameters[0] = new ReportingService.ParameterValue();

    parameters[0].Name = "SelectedTable";

    parameters[0].Value = selectedTable;

    ReportingService.DataSourceCredentials[] credentials = null;

    string showHideToggle = null;

    string encoding;

    string mimeType;

    ReportingService.Warning[] warnings = null;

    ReportingService.ParameterValue[] reportHistoryParameters = null;

    string[] streamIDs = null;

    ReportingService.SessionHeader sh = new ReportingService.SessionHeader();

    rs.SessionHeaderValue = sh;

    try

    {

    result = rs.Render(reportPath, format, historyID, devInfo, parameters, credentials,

    showHideToggle, out encoding, out mimeType, out reportHistoryParameters, out warnings,

    out streamIDs);

    string filename = "";

    FileStream stream = File.Create(filename, result.Length);

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

    stream.Close();

    System.Diagnostics.Process.Start(filename);

    }

    catch (System.Web.Services.Protocols.SoapException e)

    {

    System.Windows.Forms.MessageBox.Show(e.Message);

    }

  • shai.dory

    SSC Journeyman

    Points: 79

    Hi there

    you are probably using sql server 2008 and in that version they removed the SessionHeader class you should use the ReportExecutionService class of 2008

    here is the link that can help you get started :

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

    🙂

  • derekwalters77

    SSC Rookie

    Points: 25

    I have used ZetPDF.com which is a good platform that generate pdf files on C#.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply