Mohammed Atef’s Technical blog

Download crystal report as pdf

you can use the following method in any .net application for download crystal reports as pdf file.

 private void  DownloadReport(ReportDocument rpt,string appName)
{
DiskFileDestinationOptions crDiskFileDestinationOptions =
new DiskFileDestinationOptions();
string _filePath = string.Format(“{0}{1}.pdf”, System.IO.Path.GetTempPath(), System.Guid.NewGuid()); 

 

//set ExportOptions properties
crDiskFileDestinationOptions.DiskFileName = _filePath;
rpt.ExportOptions.DestinationOptions = crDiskFileDestinationOptions;
rpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
rpt.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
// Export the report
rpt.Export();
// The following code writes the pdf file to the Clients browser.
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = “application/pdf”;
Response.AppendHeader(“Content-Disposition”,”attachment; filename=” +appName+ “.pdf”);
Response.WriteFile(_filePath);
Response.Flush();
Response.Close();
// delete the exported file from disk
System.IO.File.Delete(_filePath);
}

January 29, 2009 Posted by | Developement | , | Leave a Comment

   

Follow

Get every new post delivered to your Inbox.