2 // System.Web.UI.HtmlControls.HtmlInputFile.cs
5 // Dick Porter <dick@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections.Specialized;
30 using System.ComponentModel;
31 using System.Security.Permissions;
33 namespace System.Web.UI.HtmlControls
36 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 [ValidationProperty ("Value")]
40 public class HtmlInputFile : HtmlInputControl , IPostBackDataHandler
42 public HtmlInputFile () : base ("file")
47 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
48 [WebSysDescription("")]
52 string acc = Attributes["accept"];
55 return (String.Empty);
62 Attributes.Remove ("accept");
64 Attributes["accept"] = value;
70 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
71 [WebSysDescription("")]
75 string maxlen = Attributes["maxlength"];
80 return (Convert.ToInt32 (maxlen));
85 Attributes.Remove ("maxlength");
87 Attributes["maxlength"] = value.ToString ();
92 HttpPostedFile posted_file;
95 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
96 [WebSysDescription("")]
98 public HttpPostedFile PostedFile
101 return (posted_file);
106 [DefaultValue ("-1")]
110 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
111 [WebSysDescription("")]
112 [WebCategory("Appearance")]
116 string size = Attributes["size"];
121 return (Convert.ToInt32 (size));
126 Attributes.Remove ("size");
128 Attributes["size"] = value.ToString ();
134 public override string Value
137 HttpPostedFile file = PostedFile;
141 return file.FileName;
144 throw new NotSupportedException ("The value property on HtmlInputFile is not settable.");
153 override void OnPreRender (EventArgs e)
155 base.OnPreRender (e);
157 if (Page != null && !Disabled) {
158 Page.RegisterRequiresPostBack (this);
160 Page.RegisterEnabledControl (this);
164 HtmlForm form = (HtmlForm) SearchParentByType (typeof (HtmlForm));
165 if (form != null && form.Enctype == "")
166 form.Enctype = "multipart/form-data";
169 Control SearchParentByType (Type type)
171 Control ctrl = Parent;
172 while (ctrl != null) {
173 if (type.IsAssignableFrom (ctrl.GetType ())) {
182 bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
184 posted_file = Page.Request.Files [postDataKey];
189 void RaisePostDataChangedEventInternal ()
191 /* No events to raise */
195 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
197 return LoadPostDataInternal (postDataKey, postCollection);
200 protected virtual void RaisePostDataChangedEvent ()
202 RaisePostDataChangedEventInternal ();
206 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
209 return LoadPostData (postDataKey, postCollection);
211 return LoadPostDataInternal (postDataKey, postCollection);
215 void IPostBackDataHandler.RaisePostDataChangedEvent ()
218 RaisePostDataChangedEvent ();
220 RaisePostDataChangedEventInternal ();