Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System.Web.Mvc / System.Web.Mvc / FileResult.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System;\r
15     using System.Net.Mime;\r
16     using System.Web;\r
17     using System.Web.Mvc.Resources;\r
18 \r
19     public abstract class FileResult : ActionResult {\r
20 \r
21         protected FileResult(string contentType) {\r
22             if (String.IsNullOrEmpty(contentType)) {\r
23                 throw new ArgumentException(MvcResources.Common_NullOrEmpty, "contentType");\r
24             }\r
25 \r
26             ContentType = contentType;\r
27         }\r
28 \r
29         private string _fileDownloadName;\r
30 \r
31         public string ContentType {\r
32             get;\r
33             private set;\r
34         }\r
35 \r
36         public string FileDownloadName {\r
37             get {\r
38                 return _fileDownloadName ?? String.Empty;\r
39             }\r
40             set {\r
41                 _fileDownloadName = value;\r
42             }\r
43         }\r
44 \r
45         public override void ExecuteResult(ControllerContext context) {\r
46             if (context == null) {\r
47                 throw new ArgumentNullException("context");\r
48             }\r
49 \r
50             HttpResponseBase response = context.HttpContext.Response;\r
51             response.ContentType = ContentType;\r
52 \r
53             if (!String.IsNullOrEmpty(FileDownloadName)) {\r
54                 // From RFC 2183, Sec. 2.3:\r
55                 // The sender may want to suggest a filename to be used if the entity is\r
56                 // detached and stored in a separate file. If the receiving MUA writes\r
57                 // the entity to a file, the suggested filename should be used as a\r
58                 // basis for the actual filename, where possible.\r
59                 ContentDisposition disposition = new ContentDisposition() { FileName = FileDownloadName };\r
60                 string headerValue = disposition.ToString();\r
61                 context.HttpContext.Response.AddHeader("Content-Disposition", headerValue);\r
62             }\r
63 \r
64             WriteFile(response);\r
65         }\r
66 \r
67         protected abstract void WriteFile(HttpResponseBase response);\r
68 \r
69     }\r
70 }\r