ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

ToBytes

Converts a file on a given path to a byte array.

Source

public static byte[] ToBytes(this string fileName)
{
   if(!File.Exists(fileName))
     throw new FileNotFoundException(fileName);

   return File.ReadAllBytes(fileName);
}

Example

var bytes = @"C:\Temp\Products.pdf".ToBytes();

Author: Kris Bulté

Submitted on: 8 aug. 2012

Language: C#

Type: System.String

Views: 6633