converting a file to an array of bytes.

Asked By azy mohammadi
07-Nov-09 05:16 AM
Earn up to 0 extra points for answering this tough question.

hi,how can I convert a file to an array of  bytes?

thanks 

  C# code you can translate

  re

Web Star replied to azy mohammadi
07-Nov-09 10:53 AM

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
}

  recieve the file?

azy mohammadi replied to Robbe Morris
12-Nov-09 02:14 PM
hi,when I converted the file to an array of bytes ,and I sent it to another computer in my lan ,where this array of file will  save and how can I save it to a specific folder? 
  Using the FileStream again
Create New Account