0

I am using Microsoft SQL server database file (file with .mdf extension) as the database.

I managed to save files into the SQL table as varbinary(max). Now my question is : How do I get back the files?

I am thinking I may still need to use SELECT statement to get the file from the SQL table. However how do I save the file to my hard disk from its current binary format? What are the procedures to do that?

user3437460
  • 17,253
  • 15
  • 58
  • 106
  • [Retrieve varbinary(MAX) from SQL Server to byte in C#](http://stackoverflow.com/questions/7724550/retrieve-varbinarymax-from-sql-server-to-byte-in-c-sharp) then `File.WriteAllBytes()` – Alex K. Jan 27 '15 at 18:18
  • @AlexK. thanks a lot for your useful comment. Do you want to write do your solution for the `File.WriteAllBytes()` ? I will definitely you give vote up + accept solution if it works. – user3437460 Jan 27 '15 at 18:22
  • It's pretty much covered in the linked question, you can answer your own question with your solution including the file save and then accept it yourself if you think it'll help others. – Alex K. Jan 27 '15 at 18:29
  • @AlexK. I probably will do that. Actually I really wanted to thank you by voting up your rep points for giving me a direction so quickly, that's I ask whether you would want to put down your solution. – user3437460 Jan 27 '15 at 18:33
  • @AlexK. Is there anyway to get back the original file format? E.g. `.zip`, `docx`, `txt` using the method you mentioned? – user3437460 Jan 27 '15 at 18:40
  • You have binary data, the file extension doesn't matter, it's just part of the filename. If you are saving this binary data as a file, just make sure the filename has the correct extension. – Didaxis Jan 27 '15 at 21:21
  • Save the file name in the DB when you save the file – Alex K. Jan 28 '15 at 11:06

0 Answers0