I have been all over the net reading samples to this, they are not for ASP 2.0 or the example code given does not work.
So could someone PLEASE put this simple thing in black and white?
Assuming you have created a blank aspx lets say Downloading.aspx and are going to hyperlink from links.aspx... and all your files that you want available for the client to download are stored in a public folder on your domain lets say mydomain/downloadstuff.
1. Example of hyperlink to use on links.aspx
2. Code to use on downloading.aspx (assume to use the octet thing that supports all types of files) and does the code go in downloading.aspx or downloading.aspx.vb
if you are giving a simple hyperlink to download the File(whatever..) Just put the link to that file i.e.
Download. it will be down loaded autometically in virtual server. in case of you are not using hyperlink i.e. using Button or ImageButton then code will be on Downloading.aspx.vb and it should be look like
Response.Redirect("myDomain/DownloadStuff/DownloadIT.exe").. I wish it may help you.
I think you may be after something a bit different
Lets say you have 10 download links on one page Called "Products.aspx".
Lets make this our item list
<div mce_keep="true">item_1</div>
<div mce_keep="true">item_2</div>
<div mce_keep="true">item_3</div>
<div mce_keep="true">item_4</div>
<div mce_keep="true">item_5</div>
<div mce_keep="true">item_6</div>
<div mce_keep="true">item_7</div>
<div mce_keep="true">item_8</div>
<div mce_keep="true">item_9</div>
<div mce_keep="true">item_10</div>
Ok now think of those as links. If you click a link that is a download we are taken to a page lets call it DownLoad.aspx
For each item you can have its own script query that looks lik this "Download.aspx?i=1" and Download.aspx?i=2 and so on. To do this would only take a few minutes you would store the info in an xml with the item id and the virtual path to the actual download
destination.
Once you have done this you will find it really easy to build.
If this is what your looking at doing let me know.. [:D]
Classifieds Starter Kit
Trading Center is a Continuation of the Classifieds Starter Kit onCode Plex.
With all the talk of right and wrong ways of doing this I dont know which way to go, I know the simple call of having the browser throw up the download box works, here is an example:
<a href="http://www.mydomain.com/Downloads/MyFile.zip">Download MyFile.zip</a>, (put this where ever you want the hyperlink)
But I have read that this is no longer the way to do it, that you should call through a seperate page using the write method.
So what is the right way to be doing it and what is an example?
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/>"));
}
}
Well all of these work but I was looking for the proper way of going about this and have chosen Vince Xu's way. It seems to be the most secure and allows for tracking what is downloaded and I can easily add in a way to get the clients ip.
This may be a newbie comment but do you just copy the raw code detailed here into respective files links and downloads then once upload just navigate to links.aspx?
BradZynda
Well all of these work but I was looking for the proper way of going about this and have chosen Vince Xu's way. It seems to be the most secure and allows for tracking what is downloaded and I can easily add in a way to get the clients ip.
I believe you should put the code into the links.aspx.vb and the same for the downloads putting it directly into the aspx page should cause some errors. The vb page should be created at the same time you create the aspx.
BradZynda
Member
3 Points
38 Posts
How to Download a file with a hyperlink
Jan 13, 2008 12:17 AM|LINK
I have been all over the net reading samples to this, they are not for ASP 2.0 or the example code given does not work.
So could someone PLEASE put this simple thing in black and white?
Assuming you have created a blank aspx lets say Downloading.aspx and are going to hyperlink from links.aspx... and all your files that you want available for the client to download are stored in a public folder on your domain lets say mydomain/downloadstuff.
1. Example of hyperlink to use on links.aspx
2. Code to use on downloading.aspx (assume to use the octet thing that supports all types of files) and does the code go in downloading.aspx or downloading.aspx.vb
thanks,
Brad Zynda
vik20000in
All-Star
25882 Points
3993 Posts
MVP
Re: How to Download a file with a hyperlink
Jan 13, 2008 06:33 AM|LINK
The link the hyperlink to the virtual path of the physical file. so ur link should be something like
mydomain/downloadstuff/filename.txt
Now when the user clicks the link the file will be downloaded itself.
www.vikramlakhotia.com
Please mark the answer if it helped you
Manoj_sahu
Member
11 Points
14 Posts
Re: How to Download a file with a hyperlink
Jan 13, 2008 02:13 PM|LINK
New Delhi
Spider Maste...
Participant
1664 Points
483 Posts
Re: How to Download a file with a hyperlink
Jan 13, 2008 02:53 PM|LINK
I think you may be after something a bit different
Lets say you have 10 download links on one page Called "Products.aspx".
Lets make this our item list
Ok now think of those as links. If you click a link that is a download we are taken to a page lets call it DownLoad.aspx
For each item you can have its own script query that looks lik this "Download.aspx?i=1" and Download.aspx?i=2 and so on. To do this would only take a few minutes you would store the info in an xml with the item id and the virtual path to the actual download destination.
Once you have done this you will find it really easy to build.
If this is what your looking at doing let me know.. [:D]
Trading Center is a Continuation of the Classifieds Starter Kit onCode Plex.
BradZynda
Member
3 Points
38 Posts
Re: How to Download a file with a hyperlink
Jan 13, 2008 05:21 PM|LINK
With all the talk of right and wrong ways of doing this I dont know which way to go, I know the simple call of having the browser throw up the download box works, here is an example:
But I have read that this is no longer the way to do it, that you should call through a seperate page using the write method.
So what is the right way to be doing it and what is an example?
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.
BradZynda
Member
3 Points
38 Posts
Re: How to Download a file with a hyperlink
Jan 17, 2008 04:43 PM|LINK
Well all of these work but I was looking for the proper way of going about this and have chosen Vince Xu's way. It seems to be the most secure and allows for tracking what is downloaded and I can easily add in a way to get the clients ip.
Thanks guys
paul.cooperm...
Member
2 Points
1 Post
Re: How to Download a file with a hyperlink
Jan 20, 2008 09:42 PM|LINK
This may be a newbie comment but do you just copy the raw code detailed here into respective files links and downloads then once upload just navigate to links.aspx?
BradZynda
Member
3 Points
38 Posts
Re: How to Download a file with a hyperlink
Jan 20, 2008 10:36 PM|LINK
I believe you should put the code into the links.aspx.vb and the same for the downloads putting it directly into the aspx page should cause some errors. The vb page should be created at the same time you create the aspx.