Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi folks,
I want to know how I can track my downloads and hide direct links.
like: http://example.com/direct.zip
to:http://example.com/download?file=direct.zip or some like this.

How can do this?
Posted

1 solution

providing file name in url is like giving the exact path. you can use the following way to achive it.

provide list of download - ables on a page. use user clicks on desirable file you will redirect it to download.aspx page with productid in querystring (download.aspx?pid=5)

at download page use this code under a switch case block with pid as cases.

this example deals with excel sheet and the best points are

1. There will no redirection of aspx page, but file will be downloaded.
2. User will not come to know the path of file from URL


Here's the code is :

C#
FileInfo file = new FileInfo(PathToExcelFile);
if (file.Exists)
{
   Response.Clear();
   Response.ClearHeaders();
   Response.ClearContent();
   Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
   Response.AddHeader("Content-Type", "application/Excel");
   Response.ContentType = "application/vnd.xls";
   Response.AddHeader("Content-Length", file.Length.ToString());
   Response.WriteFile(file.FullName);
   Response.End();
}
else
{
   Response.Write("This file does not exist.");
}


Dont forget to mark as answer.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Jun-12 22:00pm    
I recommend OP to accept this as the answer, voted 5.
--SA
Sandeep Mewara 18-Jun-12 3:16am    
Good answer. 5!
[no name] 18-Jun-12 7:10am    
Thanks everyone ... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900