File Download Button

Discussion in 'ASP .Net' started by bill, Nov 21, 2006.

  1. bill

    bill Guest

    Hi All,

    I have built an application that allows a user to download a file from the
    server. I would like to come up with a solution that works with all html
    standard compliant browsers in addition to IE6 and IE7. I would like to
    avoid leaving an empty open popup window on the screen, and even though I
    have a captive user audience that can be required to disable popup blockers
    and set security settings to trusted sites, I would like to avoid requiring
    users to do this as much as possible.

    My current solution is to call this function on a button click:

    function ShowFile(strFileName)
    {
    var reportFrame = self.frames['reportframe'];
    var loadingDiv = document.getElementById('Loadingmsg');
    reportFrame.location="blank2.html";
    loadingDiv.style.display = 'block';
    var goURL = "default.ashx?CLASSNAME=SHOWFILE2&FNAME="+strFileName+"";
    reportFrame.location=goURL;
    loadingDiv.style.display = 'none';
    }
    __________________________________
    the ASHX code behind the page is as follows:

    this.CurrentContext.Response.Clear();
    this.CurrentContext.Response.ContentType = "application/octet-stream";
    this.CurrentContext.Response.AddHeader("Content-Disposition",
    "attachment; filename=" + strDisplayFileName);
    this.CurrentContext.Response.Flush();
    CurrentContext.Response.WriteFile(strLocalPath);
    ______________________________________________
    On the web from there is a hidden div containing an anmiated gif that
    displays while the file is loading. There is also an iFrame on the page
    which is initially loaded with a blank html page with no borders set so it
    is invisible. The function works on all browsers for the most part, but some
    users have settings set up in such a way that for certain types of files
    (like text file) the file shows up in the iFrame instead of promting the
    user for downloads.

    Before this I was popping up a window with javascript, and then the window
    was redirecting to the file, and closing itself. This worked OK for a long
    time but the IE6 came on on XP SP2 and the popup blocker would disable the
    fiole download and allow the window to close without the user ever seeing
    the file.

    Do you folks have any examples of a good standard practive for a file
    download button?

    Thanks
     
    bill, Nov 21, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Do
    Replies:
    1
    Views:
    358
    William LaMartin
    Nov 28, 2003
  2. Ryan Taylor
    Replies:
    2
    Views:
    1,009
    Ryan Taylor
    Nov 10, 2004
  3. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,659
    Steve C. Orr [MVP, MCSD]
    Mar 7, 2005
  4. Sam --
    Replies:
    2
    Views:
    656
    Sam --
    Mar 17, 2005
  5. Brett  Kelly
    Replies:
    1
    Views:
    714
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
Loading...

Share This Page