将rar文件直接存数据库中的类表下载操作

  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();
            }

发布了45 篇原创文章 · 获赞 3 · 访问量 9万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章