New tests.
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlInputFile.cs
index 6c120d47da3091ca7a23d3f2cf957d9279663b4b..38fe556e5cd2c2516cf3d35f8ba83f8a15364379 100644 (file)
@@ -4,7 +4,7 @@
 // Author:
 //     Dick Porter  <dick@ximian.com>
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -39,6 +39,8 @@ namespace System.Web.UI.HtmlControls
        [ValidationProperty ("Value")]
        public class HtmlInputFile : HtmlInputControl , IPostBackDataHandler
        {
+               HttpPostedFile posted_file;
+
                public HtmlInputFile () : base ("file")
                {
                }
@@ -46,8 +48,7 @@ namespace System.Web.UI.HtmlControls
                [DefaultValue ("")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [WebSysDescription("")]
-               public string Accept 
-               {
+               public string Accept {
                        get {
                                string acc = Attributes["accept"];
 
@@ -69,8 +70,7 @@ namespace System.Web.UI.HtmlControls
                [DefaultValue ("")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [WebSysDescription("")]
-               public int MaxLength 
-               {
+               public int MaxLength {
                        get {
                                string maxlen = Attributes["maxlength"];
                                
@@ -88,30 +88,22 @@ namespace System.Web.UI.HtmlControls
                                }
                        }
                }
-
-               HttpPostedFile posted_file;
                
                [DefaultValue ("")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [WebSysDescription("")]
                [WebCategory("Misc")]
-               public HttpPostedFile PostedFile 
-               {
+               public HttpPostedFile PostedFile {
                        get {
                                return (posted_file);
                        }
                }
                
-#if NET_2_0
                [DefaultValue ("-1")]
-#else
-               [DefaultValue ("")]
-#endif
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [WebSysDescription("")]
                [WebCategory("Appearance")]
-               public int Size 
-               {
+               public int Size {
                        get {
                                string size = Attributes["size"];
                                
@@ -131,37 +123,31 @@ namespace System.Web.UI.HtmlControls
                }
                
                [Browsable (false)]
-               public override string Value 
-               {
+               public override string Value {
                        get {
-                               string value = Attributes["value"];
+                               HttpPostedFile file = PostedFile;
+                               if (file == null)
+                                       return string.Empty;
 
-                               if (value == null) {
-                                       return (String.Empty);
-                               }
-                               
-                               return (value);
+                               return file.FileName;
                        }
                        set {
                                throw new NotSupportedException ("The value property on HtmlInputFile is not settable.");
                        }
                }
 
-#if NET_2_0
-               protected internal
-#else
-               protected
-#endif         
-               override void OnPreRender (EventArgs e)
+               protected internal override void OnPreRender (EventArgs e)
                {
                        base.OnPreRender (e);
 
-                       if (Page != null) {
-                               Page.RegisterRequiresPostBack (this);
+                       Page page = Page;
+                       if (page != null && !Disabled) {
+                               page.RegisterRequiresPostBack (this);
+                               page.RegisterEnabledControl (this);
                        }
-
+                       
                        HtmlForm form = (HtmlForm) SearchParentByType (typeof (HtmlForm));
-                       if (form != null && form.Enctype == "")
+                       if (form != null && form.Enctype == String.Empty)
                                form.Enctype = "multipart/form-data";
                }
 
@@ -180,7 +166,9 @@ namespace System.Web.UI.HtmlControls
 
                bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
                {
-                       posted_file = Page.Request.Files [postDataKey];
+                       Page page = Page;
+                       if (page != null)
+                               posted_file = page.Request.Files [postDataKey];
                        
                        return (false);
                }
@@ -190,7 +178,6 @@ namespace System.Web.UI.HtmlControls
                        /* No events to raise */
                }
 
-#if NET_2_0
                protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
                {
                        return LoadPostDataInternal (postDataKey, postCollection);
@@ -200,24 +187,15 @@ namespace System.Web.UI.HtmlControls
                {
                        RaisePostDataChangedEventInternal ();
                }
-#endif         
                
                bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
                {
-#if NET_2_0
                        return LoadPostData (postDataKey, postCollection);
-#else
-                       return LoadPostDataInternal (postDataKey, postCollection);
-#endif
                }
 
                void IPostBackDataHandler.RaisePostDataChangedEvent ()
                {
-#if NET_2_0
                        RaisePostDataChangedEvent ();
-#else
-                       RaisePostDataChangedEventInternal ();
-#endif
                }
        }
 }