2 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
\r
5 // Andrew Skiba <andrews@mainsoft.com>
\r
7 // Permission is hereby granted, free of charge, to any person obtaining
\r
8 // a copy of this software and associated documentation files (the
\r
9 // "Software"), to deal in the Software without restriction, including
\r
10 // without limitation the rights to use, copy, modify, merge, publish,
\r
11 // distribute, sublicense, and/or sell copies of the Software, and to
\r
12 // permit persons to whom the Software is furnished to do so, subject to
\r
13 // the following conditions:
\r
15 // The above copyright notice and this permission notice shall be
\r
16 // included in all copies or substantial portions of the Software.
\r
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
29 using System.ComponentModel;
\r
31 using System.Web.UI;
\r
32 using System.Web.UI.HtmlControls;
\r
33 using System.Security.Permissions;
\r
36 namespace System.Web.UI.WebControls
\r
38 [ControlValueProperty ("FileBytes")]
\r
39 [ValidationProperty ("FileName")]
\r
40 [Designer ("DesignerBaseTypeNameSystem.ComponentModel.Design.IDesignerDesignerTypeNameSystem.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design)]
\r
41 [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal, Unrestricted=false)]
\r
42 [AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal, Unrestricted=false)]
\r
43 public class FileUpload : WebControl
\r
45 public FileUpload ()
\r
46 : base (HtmlTextWriterTag.Input)
\r
51 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
\r
52 [Bindable (true, BindingDirection.OneWay)]
\r
54 public byte[] FileBytes
\r
58 if (cachedBytes == null) {
\r
59 cachedBytes = new byte[FileContent.Length];
\r
60 FileContent.Read (cachedBytes, 0, cachedBytes.Length);
\r
62 return (byte [])(cachedBytes.Clone ());
\r
67 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
\r
68 public Stream FileContent
\r
72 if (PostedFile == null)
\r
75 return PostedFile.InputStream;
\r
80 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
81 public string FileName
\r
85 if (PostedFile == null)
\r
86 return string.Empty;
\r
88 return PostedFile.FileName;
\r
93 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
96 get { return PostedFile != null; }
\r
100 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
\r
101 public HttpPostedFile PostedFile
\r
105 if (Page == null || !Page.IsPostBack)
\r
107 if (Context == null || Context.Request == null)
\r
109 return Context.Request.Files[UniqueID];
\r
113 protected override void AddAttributesToRender (HtmlTextWriter writer)
\r
115 writer.AddAttribute (HtmlTextWriterAttribute.Type, "file");
\r
116 if (!string.IsNullOrEmpty (UniqueID))
\r
117 writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
\r
118 base.AddAttributesToRender (writer);
\r
121 protected internal override void OnPreRender (System.EventArgs e)
\r
123 base.OnPreRender (e);
\r
124 Page.Form.Enctype = "multipart/form-data";
\r
127 protected internal override void Render (HtmlTextWriter writer)
\r
130 Page.VerifyRenderingInServerForm (this);
\r
131 base.Render (writer);
\r
135 public void SaveAs (string filename)
\r
137 throw new NotImplementedException ();
\r