Home
Manage Your Code
Snippet: Read file and convert into byte array (C#)
Title: Read file and convert into byte array Language: C#
Description: Read file and convert into byte array Views: 208
Author: Utkarsh Shigihalli Date Added: 4/3/2008
Copy Code  
1private byte[] StreamFile(string filename)
2        {
3            FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
4
5            // Create a byte array of file stream length
6            byte[] fileData = new byte[fileStream.Length];
7
8            //Read block of bytes from stream into the byte array
9            fileStream.Read(fileData, 0, System.Convert.ToInt32(fileStream.Length));
10
11            //Close the File Stream
12            fileStream.Close();
13
14            return fileData; //return the byte data
15        }