Is converting a file to a byte array the best way to save ANY file format to disk or database var binary column?
So if someone wants to save a .gif or .doc/.docx or .pdf file, can I just convert it to a bytearray UFT8 and save it to the db as a stream of bytes?
Since it’s not mentioned what database you mean I’m assuming SQL Server. Below solution works for both 2005 and 2008.
You have to create table with
VARBINARY(MAX)as one of the columns. In my example I’ve created TableRaportywith columnRaportPlikbeingVARBINARY(MAX)column.Method to put
fileinto database fromdrive:This method is to get
filefrom database and save it ondrive:This method is to get
filefrom database and put it asMemoryStream:This method is to put
MemoryStreaminto database: