NeatUpload 同时选择并上传多个文件

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>
 <div >
    <Upload:MultiFile ID="MultiFile1" UseFlashIfAvailable="true" runat="server" ViewStateMode="Enabled"></Upload:MultiFile>
 </div>
</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) Then
                    Directory.CreateDirectory(basePath)
                End If
                item.SaveAs(fileURL)

            Catch generatedExceptionName As Exception
                Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "", "alert('error')")
                Return
            End Try
        Next

3. 如果实际运行的时候发现不能选择多个,则在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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值