Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Why Internet Explorer not downloading files in https site with IE browser in IIS 7? With http it works. We tried do not saving encrypted files to the disk in IE and also set cache header in web.config. Still the issue persists in IE. In all other browsers its fine.
My code as follows:
C#
private void DownloadTemplate(string FileName)
 {
     try
     {

         String strFile = String.Empty;
         String[] filename;

         strFile = Server.MapPath(ConfigurationManager.AppSettings["TemplatePath"].ToString()) + FileName;

         filename = strFile.Split('\\');

         Response.Clear();
         Response.Buffer = true;// Read the original file from diskFileStream *
         Response.AddHeader("Content-Disposition", "attachment; filename=" + filename[filename.Length-1]);


         String ext = String.Empty;
         if (strFile.IndexOf(".") > 0)
             ext = (strFile.Split('.'))[1];

         if (ext.ToLower() == "txt")
             Response.ContentType = "text/html";
         if (ext.ToLower() == "xls")
             Response.ContentType = "xls/html";
         if (ext.ToLower() == "pdf")
             Response.ContentType = "application/pdf";

         ////combine the path and file name
         if (File.Exists(strFile))//open the file and process it
         {
             FileStream sourceFile = new FileStream(strFile, FileMode.Open, FileAccess.Read);
             long FileSize;
             FileSize = sourceFile.Length;
             Response.AddHeader("Content-Length", FileSize.ToString()); //*
             byte[] getContent = new byte[(int)FileSize];
             sourceFile.Read(getContent, 0, (int)FileSize);

             sourceFile.Close();
             Response.BinaryWrite(getContent);
         }
         Common.UserPageAudit(Session["User"].ToString(), "Download Templates", Session["ROLE"].ToString(), strFile + " Template downloaded");
     }
     catch (Exception ex)
     {
         Response.Redirect("../CustomError.aspx?Err=" + ex.Message.ToString(), false);
     }
 }
Posted
Updated 19-Feb-14 23:10pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900