Click here to Skip to main content
12,695,049 members (30,827 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
<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>





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 27-Jan-13 17:52pm
Updated 27-Jan-13 17: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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 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
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I hope it will be useful

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


thanking you
  Permalink  
v5

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100