How to build a download tracker?

  • Thread starter Thread starter Showjumper
  • Start date Start date
S

Showjumper

Anyone have any links describing building a download tracker - one that
would log the number of downloads in a database and describe how to send the
file to the user once they have clicker the link. Thanks..
 
Hi,
Make an aspx file where you have a download link(it can be an anchor
tag or a server control.
If you use a server control such as LinkButton use this code when it is
clicked :
create a table for the downloads for eg : with date and no_of_downloads
and call it download_tracker.
System.IO.FileInfo file = new System.IO.FileInfo(filepath);

if(file.Exists)

{

Response.Clear();

Response.AddHeader("Content-Length", file.Length.ToString());

Response.ContentType = "application/octet-stream";

Response.AppendHeader("Content-Disposition","attachment;filename=" +
file.Name);

update the no_of_downloads in download tracker table for the
corresponding day.

Response.WriteFile(file.FullName);

Response.Flush();

Response.End();

}

if you use another aspx page to do the same put it in Page_Load event of
that page..

when you click an anchor tag(client side)

It is little tricky : you need to send some client side script from that
aspx page to close that page.

Hope this helps ;

Regards,

Marshal Antony

http://www.dotnetmarshal.com
 
Back
Top