2
0

HtmlInputFile.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* System.Web.UI.HtmlControls
  2. * Authors
  3. * Leen Toelen ([email protected])
  4. */
  5. using System;
  6. using System.ComponentModel;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Globalization;
  10. using System.Collections.Specialized;
  11. namespace System.Web.UI.HtmlControls{
  12. [ValidationProperty("Value")]
  13. public class HtmlInputFile : HtmlInputControl, IPostBackDataHandler{
  14. public HtmlInputFile():base("file"){}
  15. bool IPostBackDataHandler.LoadPostData (string postDataKey,
  16. NameValueCollection postCollection)
  17. {
  18. return false;
  19. }
  20. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  21. {
  22. }
  23. [DefaultValue("")]
  24. [WebCategory("Behavior")]
  25. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  26. public string Accept{
  27. get{
  28. string attr = Attributes["accept"];
  29. if (attr != null)
  30. return attr;
  31. return String.Empty;
  32. }
  33. set{
  34. Attributes["accept"] = AttributeToString(value);
  35. }
  36. }
  37. [DefaultValue("")]
  38. [WebCategory("Behavior")]
  39. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  40. public int MaxLength{
  41. get{
  42. string attr = Attributes["maxlength"];
  43. if (attr != null)
  44. return Int32.Parse(attr, CultureInfo.InvariantCulture);
  45. return -1;
  46. }
  47. set{
  48. Attributes["accept"] = AttributeToString(value);
  49. }
  50. }
  51. [DefaultValue("")]
  52. [WebCategory("Appearance")]
  53. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  54. public int Size{
  55. get{
  56. string attr = Attributes["size"];
  57. if (attr != null)
  58. return Int32.Parse(attr, CultureInfo.InvariantCulture);
  59. return -1;
  60. }
  61. set{
  62. Attributes["size"] = AttributeToString(value);
  63. }
  64. }
  65. [DefaultValue("")]
  66. [WebCategory("Misc")]
  67. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  68. public HttpPostedFile PostedFile{
  69. get{
  70. return Context.Request.Files[RenderedName];
  71. }
  72. }
  73. protected override void OnPreRender (EventArgs e)
  74. {
  75. base.OnPreRender (e);
  76. for (Control ctrl = this.Parent; ctrl != null && !(ctrl is Page); ctrl = ctrl.Parent) {
  77. if (!(ctrl is HtmlForm))
  78. continue;
  79. HtmlForm form = (HtmlForm) ctrl;
  80. if (form.Enctype == "")
  81. form.Enctype = "multipart/form-data";
  82. break;
  83. }
  84. }
  85. #if NET_1_1
  86. [Browsable (false)]
  87. public override string Value {
  88. get {
  89. HttpPostedFile file = PostedFile;
  90. if (file == null)
  91. return "";
  92. return file.FileName;
  93. }
  94. set {
  95. throw new NotSupportedException ();
  96. }
  97. }
  98. #endif
  99. } // class HtmlInputFile
  100. } // namespace System.Web.UI.HtmlControls