The error comes since you are binding report in !IsPostBack condition. Hence report is not loaded when export button is clicked. Use the following to solve the issue
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindReport();
}
else
{
//To solve the error:
//Failed to export using the options you specified. Please check your options and try again.
if (Request.Form["__EVENTTARGET"] == CrystalReportViewer1.UniqueID)
{
BindReport();
}
}
}
private void BindReport()
{
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/CustomerReport.rpt"));
Customers dsCustomers = GetData("select * from customers");
crystalReport.SetDataSource(dsCustomers);
CrystalReportViewer1.ReportSource = crystalReport;
}
private Customers GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (Customers dsCustomers = new Customers())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}