Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# file to byte array

//Files less than 600MB
byte[] file = System.IO.File.ReadAllBytes(fileName);

//Files greater than 600MB
public byte[] FileToByteArray(string fileName)
{
    byte[] fileData = null;

    using (FileStream fs = File.OpenRead(fileName)) 
    { 
        using (BinaryReader binaryReader = new BinaryReader(fs))
        {
            fileData = binaryReader.ReadBytes((int)fs.Length); 
        }
    }
    return fileData;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #file #byte #array
ADD COMMENT
Topic
Name
2+7 =