0

the below code works if I try to download a .txt/.msg/.pdf/.png/.jpg but it fails if I try to download exccel or word files. Can anybody please help

        Response.ContentType = "APPLICATION/OCTET-STREAM";
        //Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

        fileUrl = Server.UrlDecode(fileUrl);
        System.String disHeader = "attachment; filename=\"" + fileUrl + "\"";
        Response.AppendHeader("Content-Disposition", disHeader);
        // transfer the file byte-by-byte to the response object 
        System.IO.FileInfo fileToDownload = new System.IO.FileInfo(fileUrl);
        Response.Flush();
        Response.WriteFile(fileToDownload.FullName);
nschonni
  • 4,069
  • 1
  • 28
  • 37
Vivek Rawat
  • 61
  • 1
  • 5
  • You might have to add the mimetype for word and excel in IIS. See http://stackoverflow.com/questions/179315/downloading-docx-from-ie-setting-mime-types-in-iis – clows Jul 17 '15 at 11:06
  • Thanks for your reply clows. But this should not be the problem as I have another application with same logic which downloads the excel and word files from the same location using the same IIS settings. – Vivek Rawat Jul 17 '15 at 11:48

0 Answers0