I was trying my hands on Asp .net after a long time, and then came across an interesting problem. I was trying to write a function to make a secure download of web based files, that is I was trying to hide the path of file from user, who is going to download a file from my site. Igoogled a lot, but could not find the exact thing, that I was looking for. Then I collected the pieces of codes from my search, and created that function out of it. This function can be called from any event and will initiate the download without letting users know the path of target file.
The code goes here:
public void download(string fileName, string parentDirectory)
string path = Server.MapPath(pare);
FileInfo f1 = new FileInfo(path + “/” + fileName);
Response.AddHeader(“Content-Disposition”, “attachment; filename=” + f1.Name);
Response.ContentType = “application/octet-stream”;
Response.Write(path + “/” + fileName);
Note: To use this code, one must use the System.IO namespace.