The Blog selected from xinyuxin912 saves an image to the xml file in binary format and selects the Blog from xinyuxin912.
Store an image in the xml file as a binary value.
Try {int readByte = 0; // int bytesToRead = 100; // data buffer size string fileName = ".. /.. /WriteXml. xml "; // the file to be opened // this. textBox1.Text = string. empty; // open the image file and use the image to construct a file stream FileStream fs = new FileStream (".. /.. /001.jpg", FileMode. open); // Construct a binary reader using a file stream to read the base metadata as the binary value BinaryReader br = new BinaryReader (fs); XmlTextWriter xmlTxtWt = new XmlTextWriter (fileName, Encoding. UTF8); // The Output setting code indent xmlTxtWt. formatting = Formatting. indented; // xmlTxtWt. indentation = 4; // write the statement xmlTxtWt. writeStartDocument (); xmlTxtWt. writeStartElement ("picture", "ContactDetails "," http://www.deltabis.com/Contact "); // Defines the namespace xmlTxtWt. writeStartElement ("image"); // defines the node xmlTxtWt. writeAttributeString ("imageName", "002.jpg"); // add the image attribute byte [] base64buffer = new byte [bytesToRead]; // open the buffer do {readByte = br. read (base64buffer, 0, bytesToRead); // Read data into the byte array xmlTxtWt. writeBase64 (base64buffer, 0, readByte); // Encode the binary value in the array to Base64 and write it to the XML file} while (bytesToRead <= readByte); xmlTxtWt. writeEndElement (); xmlTxtWt. writeEndElement (); XmlTxtWt. WriteEndDocument (); // xmlTxtWt. Flush (); xmlTxtWt. Close (); MessageBox. Show ("read and write ends! "); // This. textBox1.Text = ReadXml (fileName);} catch (Exception ex) {MessageBox. Show (ex. ToString ());}
The preceding figure stores an image in the Xml file as a binary value. For more information, see PHP Chinese website (www.php1.cn )!