如何在ASP.net中引入一个组件(类)啊?
//这是一个上传组件WmjWebControls
using System.Drawing;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System;
namespace upload
{
public class FileUpLoad : Panel
{
private HtmlInputFile htmlInputFile;
private Button button;
private Label label;
public FileUpLoad() : base()
{
htmlInputFile=new HtmlInputFile();
button=new Button();
button.Text="上传";
button.Click+=new EventHandler(this.Button_Click);
label=new Label();
label.Text="<font size=2>请选择上传文件的路径</font>";
this.Controls.Add(htmlInputFile);
this.Controls.Add(button);
this.Controls.Add(label);
this.Width=450;
this.Height=30;
this.BorderStyle=BorderStyle.Dotted;
this.BorderWidth=1;
}
private void Button_Click(object sender, EventArgs e)
{
System.Web.HttpPostedFile postedFile=htmlInputFile.PostedFile;
if(postedFile!=null)
{
try
{
string fileName=PathToName(postedFile.FileName);
if(!fileName.EndsWith(Extension))
{label.Text="You must select "+Extension+" file!"; return;}
if(postedFile.ContentLength>int.Parse(FileLength))
{label.Text="File too big!";return;}
postedFile.SaveAs(SavePath+fileName);
label.Text="Upload File Successfully!";
return;
}
catch(System.Exception exc){label.Text=exc.Message;return;}
}
label.Text="Please select a file to upload!";
return;
}
private string savePath="";
private string extension="";
private string fileLength="0";
//上传的文件保存在服务器上的位置默认为c:\ 这些属性一般都是在asp.net的标记中设置也可以在codebehind中设置
public string SavePath
{
get
{
if(savePath!="") return savePath;
return "c:\\";
}
set
{
savePath=value;
}
}
//上传文件的最大长度 单位k 默认为1k
public string FileLength
{
get
{
if(fileLength!="0") return fileLength;
return "1024";
}
set
{
fileLength=(int.Parse(value)*1024).ToString();
}
}
//上传文件的扩展名 默认为txt
public string Extension
{
get
{
if(extension!="") return extension;
return "txt";
}
set
{
extension=value;
}
}
public string PathToName(string path)
{
int pos=path.LastIndexOf("\\");
return path.Substring(pos+1);
}
}
}
//在这个页面中想引入它
<%@page language="C#"%>
<!--注意下面这一句是必须的-->
<%@ Register TagPrefix="upload" Namespace="upload" Assembly="WmjWebControls"%>
<html>
<head>
</head>
<body>
<form enctype="multipart/form-data" runat="server" ID="Form1">
<upload:FileUpLoad SavePath="E:\\" FileLength="3" Extension="txt" runat="server" ID="Fileupload1" />
</form>
</body>
</html>
我是在Visual Studio.net中调试的。
在生成的时候会自动将这个WmjWebControls.cs编译为WmjWebControls.dll并将它放到了项目文件根目录的\bin文件夹下。
而且生成跟本就没出错。
可是运行的时候出错:“找不到文件或程序集名称“WmjWebControls”,或找不到它的一个依赖项。”
是不是我的配置文件有问题啊?