发布时间:2025-12-09 19:17:55 浏览次数:4
neatUpload是asp.net 中可以同时上传多个文件的控件,主页:http://neatupload.codeplex.com/。
效果如下图(显示有点不正常。。。):
使用步骤:
1. 在aspx的开始加上引用的dll,以及在html代码中添加<Upload:MultiFile ID="MultiFile1" UseFlashIfAvailable="true" runat="server" ViewStateMode="Enabled"></Upload:MultiFile>。
注意:一定要把 UseFlashIfAvailable设置为"true"
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="ResourcesAddEdit.aspx.vb" Inherits="Manage_WebPages_Research_ResourcesAddEdit" %><%@ Register Assembly="Brettle.Web.NeatUpload" Namespace="Brettle.Web.NeatUpload"TagPrefix="Upload" %><%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"><title>管理</title></head><body><p ><Upload:MultiFile ID="MultiFile1" UseFlashIfAvailable="true" runat="server" ViewStateMode="Enabled"></Upload:MultiFile></p></body>2. 后台代码,公司用的是vb,为了照顾老员工。。
For Each item As Brettle.Web.NeatUpload.UploadedFile In MultiFile1.Files' 上传文件。Try'上传之前的名字Dim oldFileName As String = item.FileName'获取上传文件的文件名,包括后缀Dim ExtenName As String = System.IO.Path.GetExtension(oldFileName)'要存在硬盘上的新文件名Dim savedFileName As String = oldFileName.Substring(0, oldFileName.IndexOf("."c)) & "_" & DateTime.Now.ToString("yyyyMMddhhmm") & ExtenName'组合成要存储的文件名和目录Dim fileURL As String = Path.Combine(basePath, savedFileName)If Not Directory.Exists(basePath) ThenDirectory.CreateDirectory(basePath)End Ifitem.SaveAs(fileURL)Catch generatedExceptionName As ExceptionPage.ClientScript.RegisterClientScriptBlock(Me.GetType, "", "alert('error')")ReturnEnd TryNext3. 如果实际运行的时候发现不能选择多个,则在web.config中设置一下
<configSections><section name="neatUpload" type="Brettle.Web.NeatUpload.ConfigSectionHandler,Brettle.Web.NeatUpload" allowLocation="true"/></configSections><neatUpload useHttpModule="true" maxRequestLength="2097151" maxNormalRequestLength="4096" xmlns="http://www.brettle.com/neatupload/config/2008"/><appSettings/><httpModules><add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/><add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule,Brettle.Web.NeatUpload"/></httpModules>
转载于:https://www.cnblogs.com/ustcyc/p/3525217.html