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

How Do I...? Common Tasks QuickStart Tutorial

Go To...

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.

C# BinaryDataInXml.exe
View Source

[This sample can be found at M:\web\users\Sites\AspnetQuickStart\v2.0\QuickStart\howto\samples\Xml\BinaryDataInXml\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]

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

		
using (StringWriter sw = new StringWriter())
{
    using (XmlWriter writer = XmlWriter.Create(sw))
    {
        writer.WriteStartElement("Test");
        writer.WriteAttributeString("Length", buffer.Length.ToString());
        writer.WriteCData(Convert.ToBase64String(buffer, 0, buffer.Length));
        writer.WriteEndElement();
    }
...
}
C#



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


Hosted by MaximumASP | Found a broken link? | Contact Us | Terms and conditions | Privacy Policy | Advertise with us
� 2000 - 2008  Mindcracker LLC. All Rights Reserved