Get Bytes from files in .net

 public static byte[] GetBytesFromFile(this string PhysicalFilePath)
{
FileStream stream = null;
byte[] buffer;
try
{
stream = File.OpenRead(PhysicalFilePath);
buffer = new byte[stream.Length];
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
}
catch
{
buffer = new byte[0];
}
finally
{
if (stream != null)
{
stream.Close();
stream.Dispose();
}
}
return buffer;
}

 

 

SHARE THIS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.