I have an ASP.NET application which lets users download files from my web server.
I track the downloads, and only allow so many downloads of a file.
I have the following code to invoke the download for my users (on click of a button):
string sURL = sExternalSequenceFullPath + Session["sFilename"].ToString();
FileInfo fileInfo = new FileInfo(sURL);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Flush();
Response.WriteFile(fileInfo.FullName);
My problem is that the browser presents the user with the ability to download (save/saveas) or cancel.
Is there a way to know if the user cancelled? If they did cancel, I don’t want to count the download against them.
If not, is there another way to do with [without adding something to the client’s machine].
There is no way that I know of this can be done. I would present the user with a dialog, that would call your download code. If they selected “Yes” to the dialog, I would count that against them.
The other option is to write a plugin(Silverlight, Flash…etc) so that you have control.