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

tampsystemsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.