fileresult

How to view PDF document in MVC and not download it directly?

允我心安 提交于 2020-06-16 05:13:52
问题 I have a link on click on it an HTML page will be converted to PDF document then return this PDF file to the user. HTML code: <li><a href='@Url.Action("GetHTMLPageAsPDF", "Transaction", new { empID = employee.emplID })'>ViewReceipt</a></li> Code behind: public FileResult GetHTMLPageAsPDF(long empID) { string htmlPagePath = "anypath..."; // convert html page to pdf PageToPDF obj_PageToPDF = new PageToPDF(); byte[] databytes = obj_PageToPDF.ConvertURLToPDF(htmlPagePath); // return resulted pdf

ASP.NET MVC 3 File download: Not Working in IE8

≯℡__Kan透↙ 提交于 2019-12-24 00:17:34
问题 I have the Download that simply serves a static zip file from the local file system that works in Chrome and Firefox, but not in IE8. The website is running on localhost with SSL, but I am getting the following error message in IE. Unable to download Download/ from localhost. Unable to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later. public ActionResult Download(long batchID) { var batchFilePath = string.Format

How to return error message from FileResult method in asp.net MVC 4 application?

邮差的信 提交于 2019-12-23 08:49:41
问题 I have a fileresult method in asp.net mvc4 that returns a report in an excel file. Now how can i return an error message from this method if my conditions are not met !! Since we can only return a file from this method ?! Thnks 回答1: You can change signature of action method to public ActionResult MyMethod() and return FileResult when ModelState.IsValid==true and ViewResult when ModelState.IsValid==false 来源: https://stackoverflow.com/questions/12276044/how-to-return-error-message-from

Download file prompt when using WebAPI HttpResponseMessage

百般思念 提交于 2019-12-19 04:26:10
问题 I have a method in my API that returns a HttpResponseMessage: [HttpGet, HoodPeekAuthFilter] public HttpResponseMessage GlobalOverview() { try { StatsRepo _statsRepo = new StatsRepo(); string file = _statsRepo.IncidentData().AsCSVString(); if (file == null) { return Request.CreateResponse(HttpStatusCode.NoContent); } HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StringContent(file); result.Content.Headers.ContentType = new MediaTypeHeaderValue(

ASP MVC3 FileResult with accents + IE8 - bugged?

丶灬走出姿态 提交于 2019-12-19 03:13:29
问题 If the file name contains accents, it works as expected in Opera, FF, Chrome and IE9. But in IE8 file type is "unknown file type", and shows "file" as the file name (actually the last part of the URL). Does anyone know a workaround? Other than replacing the "special" characters in the file name? The test code: (file | new project | add controller) public class FileController : Controller { public ActionResult Index(bool? Accents) { byte[] content = new byte[] { 1, 2, 3, 4 }; return File

Redirecting to MVC ActionResult from FileResult

牧云@^-^@ 提交于 2019-12-17 19:13:05
问题 This might be a simple one but here goes: I'm implementing an excel downloadable report in my MVC3 application. I've used this method in the past and it's worked perfectly, however in this case, there is a chance that sales data may not exist for the report. Here is my code: I have a FileResult action within a Reports controller: [HttpPost] public FileResult ExcelReportDownload(ReportExcelDownloadRequest reportRequest) { ReportEngine re = new ReportEngine(); Stream report = re.GetReport

Is it possible to detect whether file actually downloaded

旧街凉风 提交于 2019-12-13 15:24:16
问题 Suppose I have a controller action method that returns FileResult . Is it possible to detect whether file was actually downloaded completely to the client? public ActionResult GetFile(int id) { DownloadInfo data = provider.GetInfo(id); this.provider.MarkDownloadStart(id); return File(Server.MapPath(data.Filename), "application/pdf"); } I do store information when action is being invoked, but that only means that someone initiated download. It doesn't give me any information on the server

ASP MVC3 FileResult with accents + IE8 - bugged?

萝らか妹 提交于 2019-11-30 20:57:31
If the file name contains accents, it works as expected in Opera, FF, Chrome and IE9. But in IE8 file type is "unknown file type", and shows "file" as the file name (actually the last part of the URL). Does anyone know a workaround? Other than replacing the "special" characters in the file name? The test code: (file | new project | add controller) public class FileController : Controller { public ActionResult Index(bool? Accents) { byte[] content = new byte[] { 1, 2, 3, 4 }; return File(content, "application/octet-stream", true.Equals(Accents) ? "dsaé.txt" : "dsae.txt"); } } test it like this:

Redirecting to MVC ActionResult from FileResult

走远了吗. 提交于 2019-11-28 09:47:29
This might be a simple one but here goes: I'm implementing an excel downloadable report in my MVC3 application. I've used this method in the past and it's worked perfectly, however in this case, there is a chance that sales data may not exist for the report. Here is my code: I have a FileResult action within a Reports controller: [HttpPost] public FileResult ExcelReportDownload(ReportExcelDownloadRequest reportRequest) { ReportEngine re = new ReportEngine(); Stream report = re.GetReport(reportRequest); return new FileStreamResult(report, "application/ms-excel") { FileDownloadName =

Stream file using ASP.NET MVC FileContentResult in a browser with a name?

不问归期 提交于 2019-11-26 16:03:29
Is there a way to stream a file using ASP.NET MVC FileContentResult within the browser with a specific name? I have noticed that you can either have a FileDialog (Open/Save) or you can stream the file in a browser window, but then it will use the ActionName when you try to save the file. I have the following scenario: byte[] contents = DocumentServiceInstance.CreateDocument(orderId, EPrintTypes.Quote); result = File(contents, "application/pdf", String.Format("Quote{0}.pdf", orderId)); When I use this, I can stream the bytes, but a OPEN/SAVE file dialog is given to the user. I would like to