<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 { } }
<a href='<%# Eval("file paht") %>'> Download </a>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)