title: How to store and retrieve .pdf, .exe file in SQL Server  2008
body: <p>I am currently working on a Windows Forms application (C#, VS 2010) and I need to create functionality that enables users to upload <code>.pdf</code>, <code>.exe</code> files into a SQL Server 2008 database and download them back. </p>
  
  <p>The problem that I have is that the file downloaded from the database is always corrupted (except <code>.txt</code> file) even though they are the same size. And I have used <code>varbinary(MAX)</code> as the file type to store the data in the database.</p>
  
  <p>Can anyone show me some example code for how to do this?</p>
  
  <p>PS: I have researched for more than a week, but still cannot find a solution to my problem, can anyone please help? Any answer will be highly appreciated.</p>