asp.net a picture into an instance code in an XML file as a binary value

Source: Internet
Author: User
This article introduces a picture in the form of binary value into the XML file in the instance code, the need for friends can refer to the copy code code as follows:




Try


   {


int readbyte = 0; //


int bytestoread = 100; Data buffer size


string fileName = ".. /..   /writexml.xml "; The file to open


//This.textBox1.Text = string.            Empty;


//Open picture file, use this picture to construct a file stream


FileStream fs = new FileStream (". /.. /001.jpg ", FileMode.Open);


//Using file flow constructs a binary reader to read the primitive data as a binary value


binaryreader br = new BinaryReader (FS);


XmlTextWriter XMLTXTWT = new XmlTextWriter (FILENAME,ENCODING.UTF8);


//Output set code indent


xmltxtwt.formatting = formatting.indented;


//xmltxtwt.indentation = 4;


//Writing statement


xmltxtwt.writestartdocument ();


xmltxtwt.writestartelement ("Picture", "ContactDetails", "http://www.jb51.net");//define namespace


xmltxtwt.writestartelement ("image"); Define Node


xmltxtwt.writeattributestring ("imagename", "002.jpg"); Add Picture Properties


byte[] Base64buffer = new Byte[bytestoread]; Open Buffer


do


    {


ReadByte = Br.      Read (Base64buffer,0,bytestoread); Reading data into a byte array


xmltxtwt.writebase64 (Base64buffer,0,readbyte); Encodes binary values in an array as Base64 and writes to an XML file


}while (Bytestoread <= readbyte);


xmltxtwt.writeendelement ();


xmltxtwt.writeendelement ();


xmltxtwt.writeenddocument ();


//Xmltxtwt.flush ();


Xmltxtwt.close ();


MessageBox.Show ("Read and write end!") ");


//This.textBox1.Text = READXML (fileName);


   }


catch (Exception ex)


   {


MessageBox.Show (ex. ToString ());


   }

Related Article

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.