Click here to Skip to main content
15,881,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<asp:DataList ID="DataList1" runat="server" RepeatColumns="1"
       RepeatDirection="Horizontal" CellPadding="2" CellSpacing="2" GridLines="Horizontal"
           ForeColor="" Font-Bold="True" Width="100%" RepeatLayout="Flow">
       <ItemTemplate>
          <table width="100%" style="font-family:Arial;font-weight:normal;color:#4b4b4b;font-size:12px;border-bottom:1px solid #CDCDCD;"><tr><td style="width:20%"><b>Class:</b></td><td>
          <asp:Label ID="ClassLabel" runat="server" Text='<%# Eval("Class") %>' />
           </td></tr>
           <tr><td>
           <b>Subject:</b></td><td>
           <asp:Label ID="SubjectLabel" runat="server" Text='<%# Eval("Subject") %>' />
          </td></tr>
           <tr><td><b>Topic:</b></td><td>
           <asp:Label ID="TopicLabel" runat="server" Text='<%# Eval("Topic") %>' />
          </td></tr>
          <tr><td>
           <b>Description:</b></td><td>
           <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />

           <asp:LinkButton ID="lbtnd" runat="server" OnClick="lbtnd_Click">Click Here To Download</asp:LinkButton>
           </td></tr>
         </table>
       </ItemTemplate>

           <SeparatorStyle BorderStyle="None" />

       </asp:DataList>





C#
protected void lbtnd_Click(object sender, EventArgs e)
    {
        LinkButton lbtn = (LinkButton)sender;
        topic2 = lbtn.Text;
      
        SqlCommand cmd = new SqlCommand("select Fileurl from OE_FileUpload where Description ='" + topic2 + "'", con);
        con.Open();
        fileurl = cmd.ExecuteScalar().ToString();
        string Vpath = "~/UploadData/" + fileurl;
        string ppath = Server.MapPath(Vpath);
        string name = Path.GetFileName(ppath);
        string ext = Path.GetExtension(ppath);
        string type = "";
        if (System.IO.File.Exists(ppath))
        {
            if (ext == ".pdf" || ext == ".PDF")
            {
                type = "Application/pdf";
            }
            else if (ext == ".JPG" || ext == ".jpg")
            {
                type = "Application/jpg";
            }
            else if (ext == ".doc" || ext == ".DOC")
            {
                type = "Application/doc";
            }
            else if (ext == ".docx" || ext == ".DOCX")
            {
                type = "Application/docx";
            }
            else if (ext == ".xls" || ext == ".XLS")
            {
                type = "Application/xls";
            }
            else if (ext == ".xlsx" || ext == ".XLSX")
            {
                type = "Application/xlsx";
            }
            else if (ext == ".zip" || ext == ".ZIP")
            {
                type = "application/x-zip-compressed";
            }
            //else if (ext == ".rar" || ext == ".RAR")
            //{
            //    type = "application/x-rar-compressed";
            //}
            else if (ext == ".rar" || ext == ".RAR")
            {
                type = "application/octet-stream";
            }
            else if (ext == ".txt" || ext == ".TXT")
            {
                type = "application/text";
            }

            if (type != "")
            {
                Response.Clear();
                Response.ClearHeaders();
                Response.ContentType = type;
                Response.AppendHeader("content-disposition", "attachment; filename=" + name);
                FileInfo info = new FileInfo(name);
                Response.Flush();
                Response.WriteFile(ppath);
                // Response.End();
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
        }
        else
        {

        }

    }
Posted
Updated 27-Jan-13 16:57pm
v2
Comments
Muthuraja Irullandi 27-Jan-13 23:06pm    
Hi,
Did you checked the below link?
http://forums.asp.net/t/1204802.aspx/1

The simplest way is to put file in solution directory and on download button click event

protected void button1_click(event args,sender d)
{
response.redirect(resourcefile.doc);
// what ever extention you have .pdf etc
}
 
Share this answer
 
I hope it will be useful

<a href='<%# Eval("file paht") %>'> Download </a>


thanking you
 
Share this answer
 
v5

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