日期:2009-12-28  浏览次数:20531 次

    把图片存放到数据库里,存为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();