Monday, January 28, 2008

Internet explorer was not able to open the Internet site. The requested site is either unavailable or can not be found.Please try again later.

       You may receive this error when you write a code that allows user to download a file instead of opening it in IE other browser. In my code I have to show Open/Save dialog for PDF file. I wrote the following code.

   1: Response.Clear();
   2: Response.Buffer = true;
   3: Response.ContentType = "application/pdf";
   4: Response.Cache.SetCacheability(HttpCacheability.NoCache);
   5: Response.AddHeader("content-disposition", "attachment;filename=test.pdf");
   6: Response.Charset = "";
   7: Response.BinaryWrite(bytContent);
   8: Response.End();

 


         When I ran the code I was getting error as "Internet explorer was not able to open the Internet site. The requested site is either unavailable or can not be found.Please try again later."


          To solve this error I just removed line 4 "SetCacheability" and everything works fine. After that I search on net to find the reason and I found really good article here.


          While surfing I found another approach to achieve this an I found it better that I used here. Rick Astral has shown that approach here.


 


Happy Programming !!