Esportare un report di Crystal Report direttamente in PDF con ASP.NET

by enrico 22. January 2009 16:36

Già creare un report alle volte non è una cosa velocissima ma quando all’utente gli viene proposta la pagina di selezione di tipologia di report da stampare, va in panico. È meglio quindi far in modo che il report creato con Crystal Report venga subito visualizzato in un file PDF.

La risoluzione è abbastanza semplice. Innanzitutto inserire gli opportuni import che sono i seguenti:

   1:  Imports CrystalDecisions.CrystalReports.Engine
   2:  Imports CrystalDecisions.Shared
   3:  Imports CrystalDecisions.Web.Design

Poi nella funzione di generazione dei report e del suo binding, inserire questo codice (oReport è di tipo ReportDocument):

   1:  Dim objMem As New MemoryStream
   2:  objMem = CType(oReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat), System.IO.MemoryStream)
   3:  oReport.Close()
   4:   
   5:  Response.Clear()
   6:  Response.AddHeader("content-disposition", "attachment;filename=Export.pdf")
   7:  Response.Buffer = True
   8:  Response.ContentType = "application/pdf"
   9:  Response.BinaryWrite(objMem.ToArray())
  10:  Response.End()

Ciao.

Be the first to rate this post

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

Tags: , ,

asp.net | Tricks & Tips | report

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by Esia Software 1.4.0.0

Informazioni sull'autore

Sono un cittadini di Trieste, ho 33 anni e faccio lo sviluppatore nella mia azienda che si chiama Esia Software.

Commenti recenti

Comment RSS

Post recenti

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Info legali

Le opinioni espresse in questo blog sono strettamente personali e ogni persona è responsabile dei commenti che inserisce.

RecentComments

Comment RSS