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