Sunday, February 25, 2007

Hi All,

This function is used to convert file into byte array. some time we require to convert file into byte to save into database or send to other system using remoting.

private byte [] StreamFile(string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open,FileAccess.Read);

// Create a byte array of file stream length
byte[] ImageData = new byte[fs.Length];

//Read block of bytes from stream into the byte array
fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));

//Close the File Stream
fs.Close();

return ImageData; //return the byte data
}

Regards
Pankaj

2 comments:

greenit said...

concise and effective, thank you pankaj

PRABHJOT SINGH said...

thanks for valuable suggestions

Post a Comment