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);
}

Advertisements

January 29, 2009 - Posted by | Developement | ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: