How Do I...Write Binary Data?
This sample illustrates how to write binary data in an XML stream. The WriteBase64 method
encodes the specified binary bytes as Base64 and writes out the resulting text.
After the binary data is written out, it is read into an XmlReader to ensure that the data is valid.
VB BinaryDataInXml.exe
The following code writes the Base64 encoded data inside the element.
Using sw As StringWriter = New StringWriter()
Using writer As XmlWriter = XmlWriter.Create(sw)
writer.WriteStartElement("Test")
writer.WriteAttributeString("Length", buffer.Length.ToString())
writer.WriteCData(Convert.ToBase64String(buffer, 0, buffer.Length))
writer.WriteEndElement()
End Using
...
End Using
VB
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.
|