详细内容
文件写入数据库与导出
发布日期:2010-03-05     点击:4781     字体:[ ]

写入:

            byte[] buffer = new byte[this.fUpload.PostedFile.ContentLength];
            Stream stream = this.fUpload.PostedFile.InputStream;
            stream.Read(buffer, 0, buffer.Length);

将buffer直接写入image类型字段

导出:

byte[] buffer = (byte[])ds.Tables[0].Rows[0]["Content"];
                Response.Clear();
                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.AppendHeader("Expires ", System.DateTime.Now.AddMinutes(30).ToString());
                HttpContext.Current.Response.AppendHeader("Pragma ", "public ");
                HttpContext.Current.Response.AppendHeader("Cache-Control ", "must-revalidate,   post-check=0,   pre-check=0 ");
                HttpContext.Current.Response.AppendHeader("Cache-Control ", "public ");

                string name = HttpUtility.UrlEncode(System.Text.UTF8Encoding.UTF8.GetBytes(ds.Tables[0].Rows[0]["Name"].ToString()));
                Response.AddHeader("Content-Disposition", "attachment; filename=" + name);
                Response.ContentType = "application/x-msdownload";

                Response.BinaryWrite(buffer);
                Response.End();

用户评论
昵称 
内容  *
验证码   
   
相关文章 更多...  
Copyright © 2010 zdbase.com All Rights Reserved. 苏ICP备15039389号 可人软件设计