📄 inputfile.cs
字号:
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Bestcomy.Web.UI.WebControls
{
/// <summary>
/// Summary description for InputFile.
/// </summary>
[ToolboxData("<{0}:InputFile runat=server></{0}:InputFile>"),Designer(typeof(InputFileDesigner))]
public class InputFile : WebControl, INamingContainer
{
/// <summary>
/// Gets or sets the text of browse button.
/// </summary>
public string Label
{
get
{
if(ViewState["inputfile_label"]==null)
ViewState["inputfile_label"] = "选择文件";
return (string)ViewState["inputfile_label"];
}
set
{
ViewState["inputfile_label"] = value;
}
}
/// <summary>
/// Gets or sets size of InputFile.
/// </summary>
[DefaultValue("")]
public int Size
{
set
{
if(value<1)
throw new ArgumentOutOfRangeException("value");
ViewState["InputFile_size"] = value;
}
get
{
if(ViewState["InputFile_size"]==null)
return -1;
return Convert.ToInt16(ViewState["InputFile_size"]);
}
}
[DefaultValue(""),Browsable(false)]
public HttpPostedFile PostedFile
{
get
{
return this.Context.Request.Files[this.UniqueID];
}
}
public InputFile() : base("BESTCOMY:INPUTFILE")
{
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
if(this.Size > 0)
writer.AddAttribute(HtmlTextWriterAttribute.Size, this.Size.ToString());
writer.AddAttribute("label",this.Label);
base.AddAttributesToRender (writer);
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write("<?XML:NAMESPACE PREFIX=BESTCOMY />"+Environment.NewLine);
writer.Write("<?IMPORT NAMESPACE=BESTCOMY IMPLEMENTATION=\"Bestcomy/InputFile.ashx\" />"+Environment.NewLine);
base.Render (writer);
}
protected override void OnInit(EventArgs e)
{
base.OnInit (e);
foreach(Control ctrl in this.Page.Controls)
{
if(ctrl is HtmlForm)
{
HtmlForm fm = (HtmlForm)ctrl;
if(fm.Enctype == string.Empty)
fm.Enctype = "multipart/form-data";
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -