Ben McCormack
Ben McCormack

Reputation: 33078

How do I convert a binary file to a byte array?

Given the path of a file (e.g. "C:\MyPicture.jpg"), how do I convert a binary file into a byte array?

I know I have a lot of .NET objects at my disposal, such as BinaryReader, FileStream, StreamReader, and others, but I'm not sure of the best method to take a binary file and convert it into byte[]. How might this be accomplished?

Upvotes: 4

Views: 8578

Answers (2)

Philippe Leybaert
Philippe Leybaert

Reputation: 171734

byte[] bytes = File.ReadAllBytes("C:\\MyPicture.jpg");

Upvotes: 6

SLaks
SLaks

Reputation: 887195

You're looking for File.ReadAllBytes(@"C:\MyPicture.jpg").

Upvotes: 8

Related Questions