public ActionResult DownloadFile(string filename) { try { byte[] filedata = _filesHelper.DownloadFile(filename); var dir = WebConfigurationManager.AppSettings["DirForFeedback"]; string filepath = dir + filename; //byte[] filedata = System.IO.File.ReadAllBytes(filepath); string contentType = MimeMapping.GetMimeMapping(filepath); var cd = new System.Net.Mime.ContentDisposition { FileName = filename, Inline = true, }; Response.Headers.Add("Content-Disposition", cd.ToString()); //View file //Download file //Öppnar excel return(File(filedata, contentType)); } catch (Exception e) { Console.WriteLine(e); ErrorManager.WriteToErrorLog("FileUploadController", "DownloadFile", e.ToString(), e.HResult, User.Identity.Name); var errorModel = new CustomErrorPageModel { Information = "Ett fel inträffade vid öppningen av återkopplingsfilen", ContactEmail = ConfigurationManager.AppSettings["ContactEmail"], }; return(View("CustomError", errorModel)); } }