ASP.NET 页面中水晶报表导出之二
string s_conn = ConfigurationSettings.AppSettings["dbConnISMS"];
SqlConnection conn = new SqlConnection(s_conn);
string sSQL = "SELECT CERTIFICATE, CERT_SIZE, CERT_FORMAT FROM T_ACCEPT_CERTIFICATE " +
"WHERE SEQ_NO = " + sSeqNo;
SqlCommand comm = new SqlCommand(sSQL, conn);
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
SqlBinary buffer = reader.GetSqlBinary(0);
string format = reader["CERT_FORMAT"].ToString();
string filename = "";
switch (format)
{
case "1":
{
filename = "Certificate.doc";
break;
}
case "2":
{
filename = "Certificate.xls";
break;
}
case "3":
{
filename = "Certificate.pdf";
break;
}
}
string certsize = reader["CERT_SIZE"].ToString();
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;FileName="+filename);
Response.AddHeader("Content-Length", certsize);
if (!buffer.IsNull)
Response.BinaryWrite(buffer.Value);
Response.End();
}