Click here to Skip to main content
15,909,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All
Iam trying to download file from the database but nothing actually happens. No error message or anything. I have even debug the code.
The code is as follows:
public void dwx(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "dw")
            {
                LinkButton lb = sender as LinkButton;
                DataListItem dlrow = lb.NamingContainer as DataListItem;
                string id = ((Label)dlrow.FindControl("Label9")).Text;
                connection();
                SqlCommand com = new SqlCommand("select FileName,FileType,Filedata from Newsu where Newsid=@id", con);
                com.Parameters.AddWithValue("@id", id);
                SqlDataReader dr = com.ExecuteReader();

                if (dr.Read())
                {
                    Response.Clear();
                    Response.Buffer = true;

                    Response.ContentType = dr["FileType"].ToString();
                    Response.AddHeader("content-disposition", "attachment;filename=" + dr["FileName"].ToString());
                    Response.Charset = "";
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.BinaryWrite((byte[])dr["Filedata"]);
                    Response.End();
                }
            }
        }


and
XML
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
               <ContentTemplate>
                <asp:Panel ID="Panel1" runat="server" BackColor="White" Width="320px"
                       Height="792px" ScrollBars="Both" Visible="true" >
                    <asp:DataList ID="DataList1" runat="server" BackColor="White"
                        ToolTip="Download file" DataKeyField="Newsid" Font-Names="Segoe UI"
                        Width="300px" onitemdatabound="DataList1_ItemDataBound" GridLines="Both" >



                        <AlternatingItemStyle BackColor="#CCCCCC" />



                        <ItemTemplate>
                        <div class="headitem">
                        <div class="heads">
                         <asp:Label ID="Label6" runat="server" Text='<%# Eval("Emailattach") %>'  Visible="false"  ></asp:Label>
                          <asp:Label ID="Label2" runat="server" Text='<%# Eval("Subject") %>'
                                Font-Names="Segoe UI" Font-Size="Medium" ForeColor="White"></asp:Label></div>
                            &nbsp;&nbsp;


                            <asp:LinkButton ID="ImageButton1" runat="server" Height="21px"
                                 BorderStyle="Solid" BorderColor="#2A2A2A"
                                Width="22px" OnCommand="dwx" CommandName="dw" >
                            <img src="images/a.png" />
                            </asp:LinkButton>


                               </div>
                                <br />
                                <div class="line">
                           &nbsp;  <asp:Label ID="Label3" runat="server" Text='<%# Eval("Line") %>'
                                Font-Names="Segoe UI" ></asp:Label> &nbsp;&nbsp;
                                &nbsp;&nbsp; <asp:Label ID="Label7" runat="server" Text='<%# Eval("Departmentdesc") %>'
                                Font-Names="Segoe UI" Font-Size="Smaller"></asp:Label>
                                <br />
                                <br />
                          <asp:Label ID="Label4" runat="server" Text='<%# Eval("Email")%> ' ></asp:Label> &nbsp;
                            <asp:Label ID="Label8" runat="server" Text='<%#Eval("Phone") %> ' ></asp:Label>

                            <div class ="times">
                            <asp:Label ID="Label5" runat="server" Text='<%# Eval("Newstime") %>'></asp:Label>
                                <asp:Label ID="Label9" runat="server" Text='<%# Eval("Newsid") %>' Visible="false"></asp:Label>
                            </div>
                            </div>
                        </ItemTemplate>

                    </asp:DataList>

      </asp:Panel>

                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="Ticker1" EventName="Tick" />


                    </Triggers>
       </asp:UpdatePanel>



I have placed a link button and upon clicking it i want to download the file...
Please help where the issue could be...thanks
Posted
Updated 2-Jan-14 12:03pm
v3

1 solution

Remove the update panel and check this or place the control(download button or link) outside the update panel.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900