You can use the following links to select a zip method you like.
Folder zipper using GZipStream:
http://www.eggheadcafe.com/tutorials/aspnet/9ce6c242-c14c-4969-9251-af95e4cf320f/zip--unzip-folders-and-files-with-c.aspx[
^]
Or a component like SharpZipLib:
http://www.icsharpcode.net/OpenSource/SharpZipLib/?[
^]
Here you have some code for storing a file into a database. (zip or whatever format you want)
try
{
string constr = "SERVER=localhost;DATABASE=master;pwd=sa;uid=sa";
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
string path = @"C:\TEMP\compressed.zip";
byte[] bytearr = File.ReadAllBytes(path);
string query = "Insert into files values(@file1)";
using (SqlCommand com = new SqlCommand(query,con))
{
com.Parameters.Add(new SqlParameter("@file1", bytearr));
com.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
throw ex;
}
The example above now takes a file and stores it into the table "files" as bytearray but as you may notice the GZipStream stores the compressed data into a stream that can easily be a memory stream instead of a file stream. This would avoid the use of a temporary file but you would do some changing to the folder zipper code.
Good luck!