文件上传控件——WebbUpload
在.aspx中,添加一个<input type="file">控件,代码如下:
这段代码中要注意,encType="multipart/form-data"这个属性一定要加入。另外,input中不必加入runat="server"。完成了这步之后,你可以在用于触发上传文件的button中绑定两个事件处理函数。
不要忘了在.cs文件中声明这个命名空间:using Webb.WAVE.Controls.Upload;
有时候可能出现UploadFile ifUp1 = webbUpload.GetUploadFile("ifUp1");这句话中的ifUp1返回一个空引用。这是由于你没有在web.config中加入下面这句:
以及在form中加入那句encType="multipart/form-data"。
1
<form id="Form1" method="post" encType="multipart/form-data" runat="server">
2
<input id="ifUp1" contentEditable="false" type="file" name="ifUp1">
3
</form>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
这段代码中要注意,encType="multipart/form-data"这个属性一定要加入。另外,input中不必加入runat="server"。完成了这步之后,你可以在用于触发上传文件的button中绑定两个事件处理函数。
1
private void ibtnSend_Load(object sender, System.EventArgs e)
2
{
3
ImageButton ibtnSender = (ImageButton)sender;
4
WebbUpload webbUpload = new WebbUpload();
5
webbUpload.RegisterProgressBar(ibtnSender);
6
}
7![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
private void ibtnSend_Click(object sender, System.Web.UI.ImageClickEventArgs e)
9
{
10
string uploadFolder = MapPath(@"Upload\");
11
WebbUpload webbUpload = new WebbUpload();
12
UploadFile ifUp1 = webbUpload.GetUploadFile("ifUp1");
13![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
if (ifUp1 != null)
15
{
16
string fileName1 = Path.GetFileName(ifUp1.ClientFullPathName);
17
ifUp1.SaveAs(uploadFolder + newFileName);
18
}
19
}
20![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
不要忘了在.cs文件中声明这个命名空间:using Webb.WAVE.Controls.Upload;
有时候可能出现UploadFile ifUp1 = webbUpload.GetUploadFile("ifUp1");这句话中的ifUp1返回一个空引用。这是由于你没有在web.config中加入下面这句:
1
<!-- Settings of WebbUpload -->
2
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="1024000" executionTimeout="900" />
3
<httpModules>
4
<add name="WebbHttpModule" type="Webb.WAVE.Controls.Upload.WebbHttpModule, Webb.WAVE.Controls.Upload"/>
5
</httpModules>
6
<httpHandlers>
7
<add verb="*" path="progress.ashx" type="Webb.WAVE.Controls.Upload.WebbUploadStatusHandler, Webb.WAVE.Controls.Upload" />
8
</httpHandlers>
9
<!-- ========================= -->
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
以及在form中加入那句encType="multipart/form-data"。