Metodo, per leggere un array di byte che rappresenta un generico file, dato il suo percorso.

C#

public static byte[] ReadFileBytes(string filePath)

{
byte[] data = null;
try
{
FileInfo fInfo = new FileInfo(filePath);
long numBytes = fInfo.Length;
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
data = br.ReadBytes((int)numBytes);
br.Close();
fs.Close();
}
catch (Exception er)
{
throw new Exception(er.Message, er);
}
return data;
}

VB.NET
Public Shared Function ReadFileBytes(ByVal filePath As String) As Byte()

Dim data() As Byte
Try
Dim fInfo As New FileInfo(filePath)
Dim numBytes As Long = fInfo.Length
Dim fs As New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
data = br.ReadBytes(CType(numBytes,Integer))
br.Close
fs.Close
Catch er As Exception
Throw New Exception(er.Message, er)
End Try
Return data
End Function