Note that there are some explanatory texts on larger screens.

plurals
  1. PODownload binary file From SQL Server 2000
    primarykey
    data
    text
    <p>I inserted binary files (images, PDF, videos..) and I want to retrieve this file to download it.</p> <p>I used generic handler page as this</p> <pre><code>public void ProcessRequest (HttpContext context) { using (System.Data.SqlClient.SqlConnection con = Connection.GetConnection()) { String Sql = "Select BinaryData From ProductsDownload Where Product_Id = @Product_Id"; SqlCommand com = new SqlCommand(Sql, con); com.CommandType = System.Data.CommandType.Text; com.Parameters.Add(Parameter.NewInt("@Product_Id", context.Request.QueryString["Product_Id"].ToString())); SqlDataReader dr = com.ExecuteReader(); if (dr.Read() &amp;&amp; dr != null) { Byte[] bytes; bytes = Encoding.UTF8.GetBytes(String.Empty); bytes = (Byte[])dr["BinaryData"]; context.Response.BinaryWrite(bytes); dr.Close(); } } } </code></pre> <p>and this is my table</p> <pre><code>CREATE TABLE [ProductsDownload] ( [ID] [bigint] IDENTITY (1, 1) NOT NULL , [Product_Id] [int] NULL , [Type_Id] [int] NULL , [Name] [nvarchar] (200) COLLATE Arabic_CI_AS NULL , [MIME] [varchar] (50) COLLATE Arabic_CI_AS NULL , [BinaryData] [varbinary] (4000) NULL , [Description] [nvarchar] (500) COLLATE Arabic_CI_AS NULL , [Add_Date] [datetime] NULL , CONSTRAINT [PK_ProductsDownload] PRIMARY KEY CLUSTERED ( [ID] ) ON [PRIMARY] , CONSTRAINT [FK_ProductsDownload_DownloadTypes] FOREIGN KEY ( [Type_Id] ) REFERENCES [DownloadTypes] ( [ID] ) ON DELETE CASCADE ON UPDATE CASCADE , CONSTRAINT [FK_ProductsDownload_Product] FOREIGN KEY ( [Product_Id] ) REFERENCES [Product] ( [Product_Id] ) ON DELETE CASCADE ON UPDATE CASCADE ) ON [PRIMARY] GO </code></pre> <p>And use data list has label for file name and button to download file as</p> <pre><code>&lt;asp:DataList ID="DataList5" runat="server" DataSource='&lt;%#GetData(Convert.ToString(Eval("Product_Id")))%&gt;' RepeatColumns="1" RepeatLayout="Flow"&gt; &lt;ItemTemplate&gt; &lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt; &lt;tr&gt; &lt;td class="spc_tab_hed_bg spc_hed_txt lm5 tm2 bm3"&gt; &lt;asp:Label ID="LblType" runat="server" Text='&lt;%# Eval("TypeName", "{0}") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td width="380" class="spc_tab_hed_bg"&gt; &amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left" class="lm5 tm2 bm3"&gt; &lt;asp:Label ID="LblData" runat="server" Text='&lt;%# Eval("Name", "{0}") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td align="center" class=" tm2 bm3"&gt; &lt;a href='&lt;%# "DownloadFile.aspx?Product_Id=" + DataBinder.Eval(Container.DataItem,"Product_Id") %&gt;' &gt; &lt;img src="images/downloads_ht.jpg" width="11" height="11" border="0" /&gt; &lt;/a&gt; &lt;%--&lt;asp:ImageButton ID="ImageButton1" ImageUrl="images/downloads_ht.jpg" runat="server" OnClick="ImageButton1_Click1" /&gt;--%&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; </code></pre> <p>I tried more to solve this problem but I cannot.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload