zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Java 验证码工具类
    Servlet实现文件下载
    SQLyog连接报错 Error No.2058 Plugin caching_sha2_password could not be loaded
    springmvc上传文件出现异常,postman测试,文件上传问题org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;
    swaager2中实现文件上传的api测试操作
    idea中无法正常显示java与jsp文件内容
    servlet容器多线程与spring单例
    ThreadLocal使用与注意事项
    mysql的分组之后取时间最大的时间的那个数据
    servlet中常见装饰类HttpServletRequestWrapper等等
  • 原文地址:https://www.cnblogs.com/ustcyc/p/3525217.html
Copyright © 2011-2022 走看看