asp.net a picture in the form of a binary value to the instance code in the XML file _ practical Tips

Source: Internet
Author: User
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 a picture file and use the picture to construct a file stream
FileStream fs = new FileStream (".. /.. /001.jpg ", FileMode.Open);
Constructs a binary reader using a file stream to read the base metadata 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 Namespaces
Xmltxtwt.writestartelement ("image"); Defining nodes
Xmltxtwt.writeattributestring ("imagename", "002.jpg"); Add Picture Properties
byte[] Base64buffer = new Byte[bytestoread]; Open buffer
Todo
{
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.