Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   |   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 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
[This sample can be found at C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\QuickStart\howto\samples\Xml\BinaryDataInXml\]

The following code writes the Base64 encoded data inside the element.

		
StringWriter sw = new StringWriter();
XmlWriter w = XmlWriter.Create(sw);
w.WriteStartElement("Test");
w.WriteAttributeString("Length", buffer.Length.ToString());
w.WriteBase64(buffer, 0, buffer.Length);
w.WriteEndElement();
C#



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright 2004 Microsoft Corporation. All rights reserved.