Option Explicit On
Option Strict On
Imports System
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim bufferSize As Integer = 1000
Dim buffer(bufferSize) As Byte
Dim readBytes As Integer = 0
Using writer As XmlWriter = XmlWriter.Create("output.xml")
Dim inputFile As New FileStream("C:\a.jpg", FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)
writer.WriteStartDocument()
writer.WriteStartElement("image")
Dim br As New BinaryReader(inputFile)
Do
readBytes = br.Read(buffer, 0, bufferSize)
writer.WriteBinHex(buffer, 0, readBytes)
Loop While bufferSize <= readBytes
br.Close()
writer.WriteEndElement()
writer.WriteEndDocument()
End Using
End Sub
End Class