Downloading a report from the SQL Azure Reporting Service

To download a rendered report from SQL Azure Report Service is more straight forward than I expected:

ServerReport report = new ServerReport();
report.ReportServerUrl = new Uri("https://xxx.reporting.windows.net/ReportServer");
report.ReportServerCredentials = new ReportServerCredentials("username", "password", "xxx.reporting.windows.net");
report.ReportPath = "/ReportName.rdl";
var bytearray = report.Render("PDF");
using (var fs = new FileStream(@"c:\file.pdf", FileMode.Create))
{
    fs.Write(bytearray, 0, bytearray.Length);
}

I’m saving the byte array to the disk, but you could just as easily write it to a blob.

The format can be and of these values:

HTML3.2, HTML4.0, MHTML, IMAGE, EXCEL, WORD, CSV, PDF, XML, and NULL

Not sure why you would want ‘null’, but there you are.

Advertisements