Page view counter

These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

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
View Source

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.