Writing Byte Array to Xml file

Posted: March 10, 2012 in .Net4.0, File Operations
Tags: , , , , ,

Today’s post is a small code snippet for you to write byte array to an xml file using FileStream and Binary Writer class’s Write method.Hope this helps 🙂

private void ByteArrayToFile(string fileName, byte[] byteArray)
{
FileStream fs = new FileStream(fileName + ".xml", FileMode.Create, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs, Encoding.Unicode);
bw.Write(byteArray);
bw.Close();
fs.Close();
}

Advertisements
Comments
  1. javaGuy says:

    🙂 Like..!! Another useful article from You.

    Will the code write to a different file each time, or can we use the code to append the byte array to an existing file.? On second thought, if you append an XML with another XML then file wouldn’t remain a well-formed XML. Would it.?

  2. I’ll right away take hold of your rss as I can not find your e-mail subscription hyperlink or newsletter service. Do you’ve any?
    Please permit me know so that I could subscribe. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s