using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; using Microsoft.Win32; namespace DownLoadFiles { public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.DropDownList DropDownList1; private void Page_Load(object sender, System.EventArgs e) { string path = MapPath("..") + "/ExUpLoads/"; string[] files = Directory.GetFiles(path,"*.*"); foreach(string file in files) { string name = Path.GetFileName(file); DropDownList1.Items.Add(name); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private static string GetContentTypeFromFileExt(string fileExtension) { RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(fileExtension); try { return regKey.GetValue( "Content Type","application/octet-stream" ).ToString(); } catch(Exception) { return "application/octet-stream"; } } private void Button1_Click(object sender, System.EventArgs e) { string pathFrom = MapPath("..") + "/ExUpLoads/"; string filename = DropDownList1.SelectedItem.Text; FileInfo file = new FileInfo(pathFrom + filename); string temp = file.FullName; Response.Clear(); Response.ContentType = GetContentTypeFromFileExt(file.Extension); Response.AppendHeader( "Content-Disposition", "attachment; filename=" + file.FullName ); Response.Flush(); temp = Response.ContentType; Response.WriteFile(file.FullName); } } } WebForm1

DownLoad Files Here