byte array to pdf

You shouldn’t be using the BinaryFormatter for this – that’s for serializing .Net types to a binary file so they can be read back again as .Net types.

If it’s stored in the database, hopefully, as a varbinary – then all you need to do is get the byte array from that (that will depend on your data access technology – EF and Linq to Sql, for example, will create a mapping that makes it trivial to get a byte array) and then write it to the file as you do in your last line of code.

With any luck – I’m hoping that fileContent here is the byte array? In which case you can just do

System.IO.File.WriteAllBytes("hello.pdf", fileContent);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)