Export Report

 

Hi,

How can i export a reporting services "report"  without using a report viewer

From C# code 

NB: i am using SQL server 2005 (RS 2005 too)

Thanks

Tarek Ghazali

SQL Server MVP

 

 



Answer this question

Export Report

  • Birol

    Hi again,

    (That will then ask the user if they want to open or save the file. The file name will be what ever the report name is.)

    Is there a way to automaticaly save it without the user intervention

    Thanks,

    Tarek


  • echom

    Hi again.

    Do you have an example for using it

    What i want to do is export the file into pdf and give it a name.

    Thanks

    Tarek Ghazali

    SQL Server MVP


  • charles_chang

    Your best bet will be to use the webservice classes in the ReportExecution2005 namespace:

    http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.aspx

    -Chris



  • skapunk60

    If you want to use URL to get the PDF version of the report, and you don't want to prompt the user, then I would recommend getting the response programmatically via the C# WebRequest class. You can provide the URL, and then get a stream back which you can just write to the filesystem.

    If you need to do anything more complicated (provide credentials for datasets, set parameters, etc...) then I would recommend using the SOAP API.

    Here is a sample bit of code. Set reportServer = your report server URL (http://localhost/ReportServer).

    string uri = string.Format(@"{0}/ /{1}&rs:Command=Render&rs:Format=PDF&rc:Toolbar=false",

    reportServer,

    reportName

    );

    WebRequest request = WebRequest.CreateDefault(new Uri(uri));

    request.UseDefaultCredentials = true;

    using (WebResponse response = request.GetResponse())

    using (Stream readStream = response.GetResponseStream())

    using (FileStream writeStream = File.OpenWrite(outputPath))

    {

    byte[] buffer = new Byte[4096];

    int bytesRead = 0;

    while (0 != (bytesRead = readStream.Read(buffer, 0, buffer.Length)))

    {

    writeStream.Write(buffer, 0, bytesRead);

    }

    }


  • SailFL

    have you tried doing it through the url it's pretty straight foward you pass what ever values and then say &rs:Format=HTML4.0(or what ever format you want)

    here's a link further explaining it

    http://msdn2.microsoft.com/en-us/library/ms154040.aspx


  • Sharat

    I don't know about renaming it but here's how you would call it with a url call

    report name: report.rdl

    parameter: ContactID

    format: pdf

    URL: http://<serverName>/ReportServer/Report&rs:Command=Render&ContactID=3&rs:Format=pdf

    That will then ask the user if they want to open or save the file. The file name will be what ever the report name is.


  • funghy

    not that I know of but if you do find a way could you post it here and let me know.
  • Export Report