CRN.Model.Individual.FileInfo info = new CRN.Model.Individual.FileInfo();
info.Option_Action = "FileID";
info.FileID = Convert.ToInt32(e.CommandArgument);
DataTable dt = BLLFileInformation.SelectIDFileInformation(info).Tables[0];
Byte[] buffer = (byte[])dt.Rows[0]["FileContent"];
#region 獲取文件的類型
string FileType = "";
string FileName = dt.Rows[0]["FileName"].ToString();
FileType = FileName.Substring(FileName.LastIndexOf('.'));
#endregion
if (FileType.ToLower() != ".rar")
{
Response.Clear();
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/msword"; //一定要寫,否則是亂碼
Response.BinaryWrite(buffer);
Response.End();
}
else
{
Response.Clear();
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/x-msdownload;Charset=utf-8";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.GetEncoding("utf-8"))); //一定要寫,否則是亂碼
Response.BinaryWrite(buffer);
Response.End();
}
將rar文件直接存數據庫中的類表下載操作
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.