- 爱易网页
-
ASP.NET教程
- 我自己写的自定义Web的上传控件
日期:2012-08-25 浏览次数:20443 次
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Design;
namespace Yingnet.Common
{
/// <summary>
/// FileUpload 的摘要说明。E:\program\Common\FileUpload.bmp
/// </summary>
[ToolboxBitmap(typeof(Yingnet.Common.FileUpload), "FileUpload.bmp"),
DefaultProperty("Text"), DefaultEvent("Click"),
ToolboxData("<{0}:FileUpload runat=server></{0}:FileUpload>")]
public class FileUpload : System.Web.UI.WebControls.WebControl {
/// <summary>
/// 上传按钮
/// </summary>
private Button button=new Button();
/// <summary>
/// 上传文件个数
/// </summary>
private int filenum=1;
/// <summary>
/// File对象
/// </summary>
private HtmlInputFile[] file;
/// <summary>
/// 保存路径,默认为系统的临时目录
/// </summary>
private string path=System.IO.Path.GetTempPath();
/// <summary>
/// 上传的文件名组
/// </summary>
private string[] filename;
/// <summary>
/// 后缀文件名组
/// </summary>
private string[] suffix;
/// <summary>
///过滤器,写法是.txt;.abc
/// </summary>
private string filter="";
/// <summary>
/// 限制文件上传大小,为0是不限制,单位是字节
/// </summary>
private int size=0;//System.ComponentModel.DefaultEventAttribute
/// <summary>
/// 上传事件
/// </summary>
[Bindable(true),Category("事件"),Description("上传后激发的事件")
]
public event EventHandler Click;
/// <summary>
/// 上传文件数
/// </summary>
[Bindable(true),
Category("参数"),Description("设定上传文件的个数"),
DefaultValue("1")]
public int FileNum{
set{
if(value<1){
value=1;
}
filenum=value;
this.Controls.Clear();
file=new HtmlInputFile[filenum];
filename=new string[filenum];
suffix=new string[filenum];
for(int i=0;i<filenum;i++) {
file[i]=new HtmlInputFile();
this.Controls.Add(file[i]);
}
this.Controls.Add(button);
}
get{
return filenum;
}
}
/// <summary>
/// 上传按钮的文本
/// </summary>
[Bindable(true),
Category("参数"), Description("设定上传文件的路径"),
DefaultValue("1")]
/// <summary>
/// 上传路径
/// </summary>
public string UploadPath {
set{
if("".Equals(value)||value==null){
value=System.IO.Path.GetTempPath();
}