当前位置:首页 » 网站技术 » ASP.NET

ASP.NET快速实现多文件上传

...

ASP.NET快速实现多文件上传

前台部分代码:
<form id="form1" runat="server">
<asp:FileUpload ID="UFile1" runat="server" /><br />
<asp:FileUpload ID="UFile2" runat="server" /><br />
<asp:FileUpload ID="UFile3" runat="server" /><br />
<asp:FileUpload ID="UFile4" runat="server" /><br />
<asp:FileUpload ID="UFile5" runat="server" /><br />
<asp:Button ID="btnUpload" Text="Demo" runat="server" OnClick="btnUpload_Click" />
</form>

后台关键代码:
protected void btnUpload_Click(object sender, EventArgs e)
{
    HttpFileCollection files = HttpContext.Current.Request.Files;
    try
    {
        for (int i = 0; i < files.Count; i++)
        {
            HttpPostedFile file = files[i];
            string filename, fileextension;
            filename = Path.GetFileName(file.FileName);
            if (filename.Length > 0)
            {
                fileextension = Path.GetExtension(filename);
                file.SaveAs(Server.MapPath("~/FormFile/") + filename);
            }
        }
    }
    catch
    { }
}
注:请修改后台代码中的:Server.MapPath("~/FormFile/"),这是上传文件存储路径!

继续阅读
6行代码实现ASP无组件上传
北京网店经营今年纳入工商监控
网上岗位有陷阱提醒学生要鉴别
广电严查21类网上视听内容 节目必须要有版权
发表评论

昵称:
最新评论
暂时没有评论!