How to export a stored procedure to PDF using ASP.NET 4.0 with C# and VS2010?
I tried the following code but get error:
Adobe Reader could not open 'xxx.PDF' because it is either not a supported file or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
------------------------
protected void Button1_Click1(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
string query = "proc_SMR_EDIT_OI_BYRPTNAME";
var cmd = new SqlCommand(query, conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
var reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
ExportTableData(dt);
}
protected void ExportTableData(DataTable dtdata)
{
string attachment = "attachment; filename=Contacts.pdf";
Response.ClearContent();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", attachment);
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
I tried the following code but get error:
Adobe Reader could not open 'xxx.PDF' because it is either not a supported file or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
------------------------
protected void Button1_Click1(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
string query = "proc_SMR_EDIT_OI_BYRPTNAME";
var cmd = new SqlCommand(query, conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
var reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
ExportTableData(dt);
}
protected void ExportTableData(DataTable dtdata)
{
string attachment = "attachment; filename=Contacts.pdf";
Response.ClearContent();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", attachment);
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}