首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

Binary变换byte[] Linq方式

2012-11-06 
Binary转换byte[] Linq方式把图片存放到数据库里,存为Image类型:HttpPostedFile UpFile this.idFile.Post

Binary转换byte[] Linq方式

把图片存放到数据库里,存为Image类型:            HttpPostedFile UpFile =this.idFile.PostedFile;   //HttpPostedFile对象,用于读取图象文件属性            int FileLength = UpFile.ContentLength;     //记录文件长度             Byte[] FileByteArray = new Byte[FileLength];    //图象文件临时储存Byte数组            if (FileLength == 0)            {                     //无图片            }            else            {                Stream StreamObject = UpFile.InputStream;       //建立数据流对像                //读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度                StreamObject.Read(FileByteArray, 0, FileLength);            } 有Linq方式保存:           v.ry_zp=FileByteArray 用Linq方式读取:         ZGGZDataContext dc = new ZGGZDataContext();        var ua = (from v in dc.ZG_RYXX                  where v.pk_code.Contains(Request.QueryString["zpid"].ToString().Trim())                  select new { zp = v.ry_zp}).First();        Response.Clear();        Response.ContentType = "image/gif";        Response.BinaryWrite((byte[])ua.ry_zp.ToArray());         Response.End();
?

热点排行