在以前的Web应用中,上传文件是个很麻烦的事,现在有了.NET,文件上传变得轻而易举。下面的这个例子实现了多文件上传功能。可以动态添加输入表单,上传的文件数量没有限制。代码如下:
MultiUpload.aspx
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MultiUpload.aspx.vb"
Inherits="aspxWeb.MultiUpload" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>多文件上传</title>
<script language="JavaScript">
function addFile()
{
var str = ''<INPUT type="file" size="50" NAME="File">''
document.getElementById(''MyFile'').insertAdjacentHTML("beforeEnd",str)
}
</script>
</HEAD>
<body>
<form id="form1" method="post" runat="server" enctype="multipart/form-data">
<center>
<asp:Label Runat="server" ID="MyTitle"></asp:Label>
<P id="MyFile"><INPUT type="file" size="50" NAME="File"></P>
<P>
<input type="button" value="增加(Add)" onclick="addFile()">
<asp:Button Runat="server" Text="上传" ID="Upload"></asp:Button>
<input onclick="this.form.reset()" type="button" value="重置(ReSet)">
</P>
</center>
<P align="center">
<asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True"
Font-Size="9pt" Width="500px" BorderStyle="None" BorderColor="White"></asp:Label>
</P>
</form>
</body>
</HTML>
后代码:MultiUpload.aspx.vb
Public Class MultiUpload
Inherits System.Web.UI.Page
Protected WithEvents Upload As System.Web.UI.WebControls.Button
Protected WithEvents MyTitle As System.Web.UI.WebControls.Label
Protected WithEvents