HtmlInputFile.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // System.Web.UI.HtmlControls.HtmlInputFile.cs
  3. //
  4. // Author:
  5. // Dick Porter <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  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:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  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.
  27. //
  28. using System.Collections.Specialized;
  29. using System.ComponentModel;
  30. namespace System.Web.UI.HtmlControls
  31. {
  32. [ValidationProperty ("Value")]
  33. public class HtmlInputFile : HtmlInputControl , IPostBackDataHandler
  34. {
  35. public HtmlInputFile () : base ("file")
  36. {
  37. }
  38. [DefaultValue ("")]
  39. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  40. public string Accept
  41. {
  42. get {
  43. string acc = Attributes["accept"];
  44. if (acc == null) {
  45. return (String.Empty);
  46. }
  47. return (acc);
  48. }
  49. set {
  50. if (value == null) {
  51. Attributes.Remove ("accept");
  52. } else {
  53. Attributes["accept"] = value;
  54. }
  55. }
  56. }
  57. [DefaultValue ("")]
  58. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  59. public int MaxLength
  60. {
  61. get {
  62. string maxlen = Attributes["maxlength"];
  63. if (maxlen == null) {
  64. return (-1);
  65. } else {
  66. return (Convert.ToInt32 (maxlen));
  67. }
  68. }
  69. set {
  70. if (value == -1) {
  71. Attributes.Remove ("maxlength");
  72. } else {
  73. Attributes["maxlength"] = value.ToString ();
  74. }
  75. }
  76. }
  77. HttpPostedFile posted_file;
  78. [DefaultValue ("")]
  79. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  80. public HttpPostedFile PostedFile
  81. {
  82. get {
  83. return (posted_file);
  84. }
  85. }
  86. #if NET_2_0
  87. [DefaultValue ("-1")]
  88. #else
  89. [DefaultValue ("")]
  90. #endif
  91. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  92. public int Size
  93. {
  94. get {
  95. string size = Attributes["size"];
  96. if (size == null) {
  97. return (-1);
  98. } else {
  99. return (Convert.ToInt32 (size));
  100. }
  101. }
  102. set {
  103. if (value == -1) {
  104. Attributes.Remove ("size");
  105. } else {
  106. Attributes["size"] = value.ToString ();
  107. }
  108. }
  109. }
  110. [Browsable (false)]
  111. public override string Value
  112. {
  113. get {
  114. string value = Attributes["value"];
  115. if (value == null) {
  116. return (String.Empty);
  117. }
  118. return (value);
  119. }
  120. set {
  121. throw new NotSupportedException ();
  122. }
  123. }
  124. #if NET_2_0
  125. protected internal
  126. #else
  127. protected
  128. #endif
  129. override void OnPreRender (EventArgs e)
  130. {
  131. base.OnPreRender (e);
  132. if (Page != null) {
  133. Page.RegisterRequiresPostBack (this);
  134. }
  135. }
  136. #if NET_2_0
  137. [MonoTODO]
  138. protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
  139. {
  140. throw new NotImplementedException ();
  141. }
  142. [MonoTODO]
  143. protected virtual void RaisePostDataChangedEvent ()
  144. {
  145. throw new NotImplementedException ();
  146. }
  147. #endif
  148. bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
  149. {
  150. posted_file = Page.Request.Files [postDataKey];
  151. return (false);
  152. }
  153. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  154. {
  155. /* No events to raise */
  156. }
  157. }
  158. }