Problem with exporting crystal Report to excel/pdf in ASP.NET using C#

Jan 2 2006 1:01 AM
Hi,
First of all a very happy new year to all of you.
Right now i am facing a problem regarding crystal report.Actually, i wanted to export the report generated in excel/pdf format, so that i can save the report. i have tried a number of ways to solve it but i couldnt. So, if anybody familiar with this problem please help me.
Following are the codes i have written.. 

--------------------------------------------------------------------------------
private CrystalReport2 report=new CrystalReport2();

// set report's dataset

report.SetDataSource(ds1);

// set report source

CrystalReportViewer1.ReportSource =report;

-----------------------------------------------------------------
ExportOptions crExportOptions =
new ExportOptions();

DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();

string Fname;

CrystalDecisions.CrystalReports.Engine.ReportDocument crReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

crReportDocument.SetDatabaseLogon("sa","talisma","TALDEV342","PeterDB");

crReportDocument.Load(@"C:\Inetpub\wwwroot\WeeklyReport\CrystalReport2.rpt");

CrystalReportViewer1.ReportSource = crReportDocument;

Fname =@"c:\try.pdf";

//CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

crDiskFileDestinationOptions.DiskFileName = Fname;

crExportOptions = crReportDocument.ExportOptions;

crExportOptions.DestinationOptions = crDiskFileDestinationOptions;

crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

crReportDocument.Export();

//The following code writes the pdf file to the Client’s browser.

Response.ClearContent();

Response.ClearHeaders();

Response.ContentType = "application/pdf";

Response.WriteFile(Fname);

Response.Flush();

Response.Close();

//delete the exported file from disk

System.IO.File.Delete(Fname);


These are the codes:

regards
Rajkumar Peter