Try Like This In there There Is No Need Of ItextShart
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Shared.Interop;
using System.IO;
bool status = false;
DataTable dt = new DataTable();
Student stu=new Student();
dt = stu.getActiveBlockStudentReport(0,Convert.ToString(ddlDepartment.SelectedValue),Convert.ToString(ddlCourses.SelectedValue),Convert.ToString(ddlStatus.SelectedValue));
try
{
if (dt != null && dt.Rows.Count>0)
{
if (File.Exists(Server.MapPath("~/ActiveBlockStudent.Pdf")))
{
System.IO.File.Delete(Server.MapPath("ActiveBlockStudent.Pdf"));
}
string rptName = Server.MapPath("~\\Reports\\rptBlockActiveStudent.rpt");
ReportDocument RptDoc = new ReportDocument();
RptDoc.Load(rptName);
RptDoc.SetDataSource(dt);
ExportOptions exportOpts1 = RptDoc.ExportOptions;
RptDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
RptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
RptDoc.ExportOptions.DestinationOptions = new DiskFileDestinationOptions();
((DiskFileDestinationOptions)RptDoc.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath("ActiveBlockStudent.Pdf");
RptDoc.Export();
RptDoc.Close();
RptDoc.Dispose();
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=ActiveBlockStudent.Pdf");
Response.WriteFile("ActiveBlockStudent.Pdf");
Response.Flush();
Response.Close();
}
if (File.Exists(Server.MapPath("~/ActiveBlockStudent.Pdf")))
{
System.IO.File.Delete(Server.MapPath("ActiveBlockStudent.Pdf"));
}
status = true;
}
else
{
status = false;
}
}
catch (Exception ex)
{
status = false;
}
if (status == false)
{
Messagebox1.Show("No Record Found.");
}