[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1196
  • Last Modified:

ASP.Net File Download - IE Automatic prompting for file downloads

We are using the following code in our application to perform file downloads.  It works great except that the users have to configure Internet Explorer IE to Enable the security setting “Automatic prompting for file downloads”.  Are we doing something wrong with this code?
private bool outfile(string DisplayName, int ByteSize, string ContentType, byte[] FileData)
        {
            bool ret = false;
            try
            {
                int BlockOf = 100000;
                int CountOf = 0;

                Response.Expires = 0;
                Response.Buffer = true;
                Response.Clear();
                Response.AddHeader("Content-Description", "File Transfer");
                Response.AddHeader("Content-type", ContentType);
                string myname = System.Web.HttpUtility.UrlPathEncode(DisplayName);  //UrlPathEncode will keep the spaces 
                Response.AddHeader("Content-Disposition", @"attachment;filename=" + myname);
                Response.AddHeader("Content-Transfer-Encoding", "binary");
                Response.AddHeader("Content-Length", ByteSize.ToString());
                Response.Charset = "UTF-8";
                Response.Flush();
                while (ByteSize > BlockOf + CountOf)
                {
                    if (Response.IsClientConnected)
                    {
                        Response.OutputStream.Write(FileData, CountOf, BlockOf);
                        Response.Flush();
                        CountOf = CountOf + BlockOf;
                    }
                    else
                    {
                        break;//prevent infinite loop if user disconnects 
                    }
                }

                if (Response.IsClientConnected)
                {
                    //Read Last Block of bytes and send
                    Response.OutputStream.Write(FileData, CountOf, (ByteSize - CountOf));
                    Response.Flush();
                    Response.End();
                }
                ret = true;
            }
            catch (System.Exception ex)
            {
                m_Error = ex.Message.ToString();
            }
            return ret;
        }

Open in new window

0
tampsystems
Asked:
tampsystems
  • 2
1 Solution
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
I think you should look at this.  

http://aspalliance.com/259
0
 
tampsystemsAuthor Commented:
That will result to the same issue I am having with the “automatic prompting for downloads” disabled using IE 7 and IE 8.  That article was posted in 2003 and in it says that it works great in IE 6.

IE 7 was when Microsoft added the security feature for “automatic prompting for downloads” and is causing this problem.  

Is there a work around that I can add to my code?  I do not want to force my clients to reconfigure their web browser.
0
 
tampsystemsAuthor Commented:
The issue we were having was because we were running the above code into a new window using javascript.  Once we set an option to run the script using window.navigate instead of window.open we were able to receive the download information bar.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now