Binary conversion byte[] LINQ method

Source: Internet
Author: User

Store the image in the database as the image type:
Httppostedfile Upfile =this.idfile.postedfile; Httppostedfile object, for reading image file properties
int filelength = Upfile.contentlength; Log file length
byte[] Filebytearray = new Byte[filelength]; Image file temporary storage byte array
if (filelength = 0)
{

}
Else
{
Stream streamobject = Upfile.inputstream; Set up a data stream pair like
Read image file data, Filebytearray for data storage, 0 for data pointer position, filelnegth for data length
Streamobject.read (Filebytearray, 0, filelength);
}
is saved in LINQ mode:
V.ry_zp=filebytearray
Read in 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}). A ();
Response.Clear ();
Response.ContentType = "Image/gif";
Response.BinaryWrite ((byte[]) Ua.ry_zp. ToArray ());
Response.End ();



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.