ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Download Binary (Byte) Data from database as ZIP file using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="suhaas121"> suhaas121</a>,</p> <p>For adding binary data to zip file you need to use <strong>AddEntry</strong> method.</p> <p>Check the below code.</p> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">protected void Zip(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;connString&#34;].ConnectionString); using (ZipFile zip = new ZipFile()) { zip.AlternateEncodingUsage = ZipOption.AsNecessary; SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = &#34;select tbn.Rawdata_img,tbn.Rawdata_tbl,tbn.Rawfilename_img,tbn.Rawfilename_tbl from tblBookNodes_IPC tbn inner join tblModule tbm on tbn.iModuleId=tbm.iModuleId where tbm.vcModuleTitle=@title&#34;; cmd.Parameters.AddWithValue(&#34;@title&#34;, txtDownload.Text.Trim()); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { byte[] bytes = (byte[])dr[&#34;Rawdata_img&#34;]; byte[] bytes_img = (byte[])dr[&#34;Rawdata_tbl&#34;]; string filename = dr[&#34;Rawfilename_img&#34;].ToString(); string filename_ipc = dr[&#34;Rawfilename_tbl&#34;].ToString(); zip.AddEntry(filename, bytes); zip.AddEntry(filename_ipc, bytes_img); } } conn.Close(); Response.Clear(); Response.BufferOutput = false; string zipName = String.Format(&#34;Zip_{0}.zip&#34;, DateTime.Now.ToString(&#34;yyyy-MMM-dd-HHmmss&#34;)); Response.ContentType = &#34;application/zip&#34;; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment; filename=&#34; + zipName); zip.Save(Response.OutputStream); Response.End(); } }</pre> <p><span style="text-decoration: underline;"><strong>VB.Net</strong></span></p> <pre class="brush: vb">Protected Sub Zip(ByVal sender As Object, ByVal e As EventArgs) Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings(&#34;connString&#34;).ConnectionString) Using zip As ZipFile = New ZipFile() zip.AlternateEncodingUsage = ZipOption.AsNecessary Dim cmd As SqlCommand = New SqlCommand() conn.Open() cmd.Connection = conn cmd.CommandType = CommandType.Text cmd.CommandText = &#34;select tbn.Rawdata_img,tbn.Rawdata_tbl,tbn.Rawfilename_img,tbn.Rawfilename_tbl from tblBookNodes_IPC tbn inner join tblModule tbm on tbn.iModuleId=tbm.iModuleId where tbm.vcModuleTitle=@title&#34; cmd.Parameters.AddWithValue(&#34;@title&#34;, txtDownload.Text.Trim()) Using dr As SqlDataReader = cmd.ExecuteReader() While dr.Read() Dim bytes As Byte() = CType(dr(&#34;Rawdata_img&#34;), Byte()) Dim bytes_img As Byte() = CType(dr(&#34;Rawdata_tbl&#34;), Byte()) Dim filename As String = dr(&#34;Rawfilename_img&#34;).ToString() Dim filename_ipc As String = dr(&#34;Rawfilename_tbl&#34;).ToString() zip.AddEntry(filename, bytes) zip.AddEntry(filename_ipc, bytes_img) End While End Using conn.Close() Response.Clear() Response.BufferOutput = False Dim zipName As String = String.Format(&#34;Zip_{0}.zip&#34;, DateTime.Now.ToString(&#34;yyyy-MMM-dd-HHmmss&#34;)) Response.ContentType = &#34;application/zip&#34; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment; filename=&#34; &amp; zipName) zip.Save(Response.OutputStream) Response.[End]() End Using End Sub</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/157996/Download-Binary-Byte-Data-from-database-as-ZIP-file-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/157996/Download-Binary-Byte-Data-from-database-as-ZIP-file-using-C-and-VBNet-in-ASPNet/Thu, 05 Sep 2019 04:41:21 GMT