There is a sample as below. link.aspx is listing all of the files avaliable in folder and click the hyperlink in link.aspx will trigger downloading this file in downloading.aspx.
link.aspx:
using System.IO;
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/downloadstuff"));
int i = 0;
foreach(FileInfo fi in di.GetFiles())
{
HyperLink HL = new HyperLink();
HL.ID = "HyperLink" + i++;
HL.Text = fi.Name;
HL.NavigateUrl = "downloading.aspx?file="+fi.Name;
Page.Controls.Add(HL);
Page.Controls.Add(new LiteralControl("<br/>"));
}
}
Vince Xu - M...
All-Star
80367 Points
6801 Posts
Re: How to Download a file with a hyperlink
Jan 15, 2008 06:22 AM|LINK
Hi,
There is a sample as below. link.aspx is listing all of the files avaliable in folder and click the hyperlink in link.aspx will trigger downloading this file in downloading.aspx.
link.aspx:
using System.IO; protected void Page_Load(object sender, EventArgs e) { DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/downloadstuff")); int i = 0; foreach(FileInfo fi in di.GetFiles()) { HyperLink HL = new HyperLink(); HL.ID = "HyperLink" + i++; HL.Text = fi.Name; HL.NavigateUrl = "downloading.aspx?file="+fi.Name; Page.Controls.Add(HL); Page.Controls.Add(new LiteralControl("<br/>")); } }downloading.aspx:
Hope it helps.