locked
Using HTTPHandler for file downloading RRS feed

  • Question

  • User189136008 posted

    Hi All,

    I have an ASP.NET(3.5) web application. My app. generates excel/pdf reports for users.

    I use Response.TransmitFile to make users download the report. It can take some time(~5 mins.) to produce a report. I don't want users to click "Report" button while report is generated.

    I disable "Report" button in javascript when it is pressed but I cannot enable again after I use Response.TransmitFile.

    I don't want to enable the button manually after some time in javascript or add a cookie to Response and check it continuously in javascript whether cookie is created or not.

    Is there a way to deal with this by using HTTPHanlder or any other suggestions?

    Thanks.

    Monday, December 26, 2011 4:44 AM

Answers

  • User-168800120 posted
    <asp:HyperLink id="hyperlink1" 
                                                         Text="Download"
                                       runat="server"/>  
     
    InCode Behind :
    hyperlink1.NavigateUrl = "Handler.ashx?file="+"filename";
     
     
    <%@ WebHandler Language="C#" Class="Handler" %>
    
    using System;
    using System.Web;
    
    public class Handler : IHttpHandler {
    
        public void ProcessRequest (HttpContext context) {
    
    	HttpResponse r = context.Response;
    	r.ContentType = "image/png";
    	//
    	// Write the requested image
    	//
    	string file = context.Request.QueryString["file"];
    
    // Get Data From Database. And write file.
    	if (file == "logo")
    	{
    	    r.WriteFile("Logo1.png");
    	}
    	else
    	{
    	    r.WriteFile("Flower1.png");
    	}
        }
    
        public bool IsReusable {
    	get {
    	    return false;
    	}
        }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 26, 2011 11:12 AM

All replies

  • User-168800120 posted

    Yes you can done through httpHandler. Give Handler relative path to hyperlink. Send input parameters in query string.And access data from your storage. and write the content.

    Monday, December 26, 2011 10:26 AM
  • User189136008 posted

    Hi,

    I am not familiar with HTTPHandler concept.

    Could you share an example?

    Thanks.

    Yes you can done through httpHandler. Give Handler relative path to hyperlink. Send input parameters in query string.And access data from your storage. and write the content.

    Monday, December 26, 2011 10:39 AM
  • User-168800120 posted
    <asp:HyperLink id="hyperlink1" 
                                                         Text="Download"
                                       runat="server"/>  
     
    InCode Behind :
    hyperlink1.NavigateUrl = "Handler.ashx?file="+"filename";
     
     
    <%@ WebHandler Language="C#" Class="Handler" %>
    
    using System;
    using System.Web;
    
    public class Handler : IHttpHandler {
    
        public void ProcessRequest (HttpContext context) {
    
    	HttpResponse r = context.Response;
    	r.ContentType = "image/png";
    	//
    	// Write the requested image
    	//
    	string file = context.Request.QueryString["file"];
    
    // Get Data From Database. And write file.
    	if (file == "logo")
    	{
    	    r.WriteFile("Logo1.png");
    	}
    	else
    	{
    	    r.WriteFile("Flower1.png");
    	}
        }
    
        public bool IsReusable {
    	get {
    	    return false;
    	}
        }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 26, 2011 11:12 AM