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 ());
}