String strTemp = System. Web. HttpUtility. UrlEncode (strName, System. Text. Encoding. UTF8); // fix file name garbled characters
Protected string strConn = Common. Config. getdeleettingskeyvalue ("DBConnectString ");
Protected System. Data. OleDb. OleDbConnection conn;
Protected System. Data. OleDb. OleDbCommand cmd;
Protected System. Data. OleDb. OleDbDataReader dr;
Private void Download (string field, string id)
{
Try
{
String strCmd = "select * from doc_body where id =" + id;
Conn = new OleDbConnection (strConn );
Cmd = new OleDbCommand (strCmd, conn );
Conn. Open ();
Dr = cmd. ExecuteReader ();
Dr. Read ();
Int nSize = (int) dr ["doc_size"];
String strContentType = (string) dr ["ContentType"];
String strName = (string) dr ["doc_name"];
Byte [] data = (byte []) dr [field];
If (nSize = 0)
{
Message. Text = "<font color = # 0000ff> NO File Download! </Font> ";
}
Else
{
Response. Clear ();
Response. Buffer = true;
// Response. Charset = "UTF-8 ";
// Response. ContentEncoding = System. Text. Encoding. GetEncoding ("UTF-8 ");
// UTF-8, gb2312, big5
Response. ContentType = strContentType;
// Application/ms-excel, application/ms-word, application/ms-txt, application/ms-html, or other browsers can directly support documents
String strTemp = System. Web. HttpUtility. UrlEncode (strName, System. Text. Encoding. UTF8); // fix file name garbled characters
Response. AppendHeader ("content-disposition", "attachment; filename =" + strTemp); // download the attachment
// Response. AppendHeader ("content-disposition", "online; filename =" + strName); // Open online
Response. OutputStream. Write (data, 0, nSize );
}
}
Catch (Exception exp)
{
Common. utility. MessageBox (this, "Download failed! \ N error Message: \ n "+ exp. Message );
}
Finally
{
Conn. Close ();
}
}