Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
WriteBinHex Method

XmlWriter.WriteBinHex Method

When overridden in a derived class, encodes the specified binary bytes as BinHex and writes out the resulting text.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

public virtual void WriteBinHex (
	byte[] buffer,
	int index,
	int count
)
public void WriteBinHex (
	byte[] buffer, 
	int index, 
	int count
)
public function WriteBinHex (
	buffer : byte[], 
	index : int, 
	count : int
)

Parameters

buffer

Byte array to encode.

index

The position in the buffer indicating the start of the bytes to write.

count

The number of bytes to write.

Exception typeCondition

ArgumentNullException

buffer is a null reference (Nothing in Visual Basic).

ArgumentException

The buffer length minus index is less than count.

ArgumentOutOfRangeException

index or count is less than zero.

The following example uses the WriteBinHex method to write BinHex data. The BinHex data is embedded within an <image> element.


public static void BinHexEncodeImageFile() {

  int bufferSize = 1000;
  byte[] buffer = new byte[bufferSize];
  int readBytes = 0;
	
  using (XmlWriter writer = XmlWriter.Create("output.xml")) {
       FileStream inputFile = new FileStream(@"C:\artFiles\sunset.jpg", FileMode.OpenOrCreate, 
                                                                    FileAccess.Read, FileShare.Read);
       writer.WriteStartDocument();
       writer.WriteStartElement("image");
       BinaryReader br = new BinaryReader(inputFile);
       Console.WriteLine("\r\nWriting BinHex data...");

       do {
          readBytes = br.Read(buffer, 0, bufferSize);
          writer.WriteBinHex(buffer, 0, readBytes);
       } while (bufferSize <= readBytes);
       br.Close();

    writer.WriteEndElement();// </image>
    writer.WriteEndDocument();
		
  }
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft