Maybe IHttpHandler or not. Please how to get if users successfully downloaded server documents and then increase the Total Download based on the Download Button Click.
<asp:Button ID="AS" runat="server" Text="DownLoad Here" CssClass="mainBtn" OnClientClick="CallHandler();" />
public class DownloadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string fileName =
context.Request.QueryString["filename"].ToString();
string fileWithPath = Server.MapPath("~/File/" + fileName);
FileInfo file = new System.IO.FileInfo(fileWithPath);
if (file.Exists)
{
try
{
//SQL
INSERT INTO file (count) VALUES(
SELECT TOP 1 (count + 1) FROM file ORDER BY count DESC)
SET @DCount = SELECT TOP 1 (count + 1) FROM file ORDER BY count DESC)
// set count to Label
lblCount.Text = @DCount;
}
catch (Exception)
{
//handle
}
//return the file
context.Response.Clear();
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
context.Response.AddHeader("Content-Length", file.Length.ToString());
context.Response.ContentType = "application/octet-stream";
context.Response.WriteFile(file.FullName);
context.ApplicationInstance.CompleteRequest();
context.Response.End();
}
}
public bool IsReusable
{
get { return true; }
}
}
function CallHandler()
{
$.ajax({
url: "DownloadHandler.ashx",
contentType: "application/json; charset=utf-8",
dataType: "json",
data:
{
filename: 'read.pdf'
},
responseType: "json",
success: OnComplete,
error: OnFail
});
return false;
} //Function CallHandler ends here
function OnComplete(response) {
debugger;
alert('download completed');
//increase label count
}
function OnFail(response) {
alert('Request Failed');
}
Thanks