.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Read File Data into Byte Array Format

Posted By:Ravi Ranjan Kumar       Posted Date: July 30, 2011    Points: 40    Category: File Operation    URL: http://www.dotnetspark.com  

This Code snippet enable you to learn how to Convert a file to Byte Array format.

Using File.ReadAllByte() funtion its very easy to read textfile in Byte format.
here I am going to mention a function which enable you to convert Text file data to Byte format.
take a look how 

Mention IO namespace in your program to access File class. as 
using System.IO;
and the you can create a function ReadFileinByte(string filename)

  public static byte[] ReadFileinByte(string filename)
            byte[] byteArray = File.ReadAllBytes(filename);
            return byteArray;
This ReadFileinByte function responsible to take a parameter in form of Filename and then return it with complete Byte[] array format.

How to use it

Take a look how to use ReadFileinByte function
byte[] arr = ReadFileinByte("C:\\A.txt");

            for (int i = 0; i < arr.Length; i++)


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend