How to convert a file of any type into byte array?
22,732
Solution 1
It's as easy as var bytes = File.ReadAllBytes(pathToFile)
Solution 2
You can use File.ReadAllBytes for example... BEWARE that this loads the complete file into RAM...
Solution 3
Use FileStream, you provide it the path to the file and can get the array from it.
Author by
Ramya
Updated on February 09, 2020Comments
-
Ramya about 4 years
The file can be of any type ( png,bmp,jpeg,doc,docx,pdf) I have to convert the file into byte array and send to server via WebRequest where it will be converted to the corresponding file.
-
bryan about 11 yearsActually, use ybo's method. Much cleaner