Search code examples
c#sql-server-2008

How to store a zip file in sql server table


I have a problem and I do not know what to do. I am creating a application where the user can upload zip file. I want to store this file in my database. On Google I was not able to find any real solution for this. In my database I created a field of varchar(max) to store this. I am using C# and SQL server 2008 R2. Are there any solutions or guides that you can provide to me. >


Solution

    1. You can not save files as nvarchar in database. Change the column datatype to varbinary.

    2. From the code you need to convert your file to byte[] as like below.

      byte[] bytes = System.IO.File.ReadAllBytes(filename);

    3. Now save it into database as usual way.