写入:
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();