Exportando um relatório .rdlc para PDF

by Stiven 4. March 2009 09:59

Para aqueles que gostam de relatórios em PDF e não querem passar pelo processo de selecionar o formato do relatório a ser exportado no ReportViewer, utilize a função abaixo:

    public static void ExportReportToPDF(HttpContext context, Microsoft.Reporting.WebForms.ReportViewer rViewer)

    {

        Microsoft.Reporting.WebForms.Warning[] warnings;

        string[] streamids;

        string mimeType = "";

        string encoding = "";

        string extension = "";

        byte[] bytes = rViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);

 

        context.Response.Buffer = true;

        context.Response.Clear();

        context.Response.ContentType = mimeType;

        context.Response.AddHeader("content-disposition", "outline; filename=myfile." + extension);

        context.Response.BinaryWrite(bytes);

        context.Response.Flush();

    }

 

Para exportar para excel, basta alterar de:

 

 byte[] bytes = rViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);

 

para:

 

 byte[] bytes = rViewer.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamids, out warnings);

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.Net | Dicas

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

Sobre o autor



Meu nome é Stiven Fabiano da Câmara e sou desenvolvedor de software especializado na plataforma .NET da Microsoft, utilizando a linguagem Visual C#.