From 71f0d756b31e0debdfff2c35b9139a00fb4e209a Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 6 Jun 2015 01:43:36 +0200 Subject: [PATCH] Adds file names at download from MVC web API --- web/ApiControllers/FrontOfficeApiController.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/web/ApiControllers/FrontOfficeApiController.cs b/web/ApiControllers/FrontOfficeApiController.cs index 2f05763d..faf80669 100644 --- a/web/ApiControllers/FrontOfficeApiController.cs +++ b/web/ApiControllers/FrontOfficeApiController.cs @@ -23,6 +23,7 @@ using System.Collections.Specialized; using Yavsc.Model; using Yavsc.Model.FrontOffice; using Yavsc.Helpers; +using System.Net.Http.Headers; namespace Yavsc.ApiControllers { @@ -93,11 +94,15 @@ namespace Yavsc.ApiControllers if (texest == null) throw new InvalidOperationException ( "Not an estimate"); - return new HttpResponseMessage () { + HttpResponseMessage result = new HttpResponseMessage () { Content = new ObjectContent (typeof(string), texest, new SimpleFormatter ("text/x-tex")) }; + result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue ("attachment") { + FileName = "estimate-" + id.ToString () + ".tex" + }; + return result; } private string estimateToTex (long estimid) @@ -156,11 +161,16 @@ namespace Yavsc.ApiControllers LocalizedText.Estimate_not_found)) }; - return new HttpResponseMessage () { + HttpResponseMessage result = new HttpResponseMessage () { Content = new ObjectContent (typeof(string), texest, - new TexToPdfFormatter ()) + new TexToPdfFormatter ()) }; + + result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue ("attachment") { + FileName = "estimate-" + id.ToString () + ".pdf" + }; + return result; } private HttpResponseMessage DefaultResponse()