Detecting if the user downloaded a file or not
I want to detect if the user has clicked on the download or the view hyperlin开发者_开发百科ks. It's a page where people can upload files and if needed they can look at files too(files uploaded by anyone). I am uploading the files using asp.NET and storing it in the sql server database. These files are then displayed on the webpage using the database and can be seen by anyone who logs in. There are multiple files on the webpage and all have view or download links(files like zip files don't have view). I want to create a functionality that allows the user who uploaded the files to see who saw his/her file. Something like a table column for the file name and everyone watching the file getting added to the column in the database. This is what I am using in the gridview:
<asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="~/DownloadFile.aspx?Id={0}" HeaderText="Download" Text="Download" />
You just need to have your download/view/links/whatever go to a server-side component which records the click in a database before serving the file.
in the HTML part use this for the button code:
<button type="button" onClick="check_download();"> Click Me </button>
and on the script part add this function
var downloaded = false;
function check_download() {
if (downloaded == true ) {
alert('You have already downloaded this file.');
return false;
} else {
downloaded = true;
document.location.href = 'http://Your.File.ToBe.Downloaded.URL';
return true;
}
}
精彩评论