Try this code:
protected void GetCTReport(string FSID)
{
try
{
ReportDocument rd = new ReportDocument();
rd.Load(Page.Server.MapPath("CementingTreatmentReport.rpt"));
rd.SetParameterValue("@FID", FSID);
rd.SetDatabaseLogon("DB_9B08BD_automobile_admin", "webclient786");
Print2Pdf(rd);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void Print2Pdf(ReportDocument rd)
{
try
{
ReportDocument cryRpt = new ReportDocument();
cryRpt = rd;
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
string strDate = DateTime.Now.ToShortDateString();
string Path = "~/ExportedReports/OptReport_NPS.pdf";
if (Path != null || Path != string.Empty)
{
if (System.IO.File.Exists(Path))
{
System.IO.File.Delete(Path);
}
}
CrDiskFileDestinationOptions.DiskFileName = Server.MapPath(Path);
CrExportOptions = cryRpt.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
cryRpt.Export();
Response.Redirect("SaveFile.ashx", false);
}
catch (Exception ex)
{
lblmsg.Visible = true;
lblmsg.Text = ex.Message.ToString();
}
}
Create one Generic Handler:
public void ProcessRequest (HttpContext context)
{
string Path = HttpContext.Current.Server.MapPath("~/ExportedReports/OptReport_NPS.pdf");
byte[] bytesPDF = System.IO.File.ReadAllBytes(Path);
if (bytesPDF != null)
{
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
string strDate = DateTime.Now.ToShortDateString();
response.AddHeader("content-disposition", "attachment;filename= OptReport_" + strDate + ".pdf");
response.ContentType = "application/octectstream";
response.BinaryWrite(bytesPDF);
response.End();
}
}
Hope it would help you.