多附件上传的方法

前台:

在<head></head>中加入下段javascript

<script language="JavaScript" type="text/javascript"> function addFileControl() { var str = '
' document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str) } </script>  <script language="JavaScript" type="text/javascript"> function addFileControl() { var str = '
' document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str) } </script>
  <script language="JavaScript">
    function addFileControl()
    {
     var str = '<br><INPUT type="file" NAME="File"  style="WIDTH: 428px; HEIGHT: 22px" > '
     document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str)
    }
  </script>

页面中加入下列控件还有一个web控件button

                    

其中在的html代码中 "增加"处加上  οnclick="addFileControl()"

“<INPUT οnclick="addFileControl()" type="button" value="增加(File)">”

后台代码

  private void Upload_Click(object sender, System.EventArgs e)
  { 
     string path="";定义上传目录
   if(System.IO.Directory.Exists(Server.MapPath(path))==true)
   {
    try
    {

     string s=path+"/";

//调用upMorefile
     upMorefile(s);
    }
    catch(Exception err)
    {
     Response.Write("<script>alert('"+err.Message+"');</script>");
    }
   }
   else
   {
       Response.Write("<script>alert('不存在该目录,无法上传,请在修改模块中增加!');</script>");
   }

  }

//上传文件

  private void  upMorefile(string paths)
  {
   //遍历File表单元素
   System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
   //状态信息
   System.Text.StringBuilder strMsg = new System.Text.StringBuilder("上传的文件信息分别为:<hr color=red>");
   int fileCount;
   //int filecount = files.Count;
   try
   {
    for(fileCount = 0;fileCount<files.Count;fileCount++)
    {
     //定义访问客户端上传文件的对象
     System.Web.HttpPostedFile postedFile = files[fileCount];
     string fileName, fileExtension;
     //取得上传得文件名
     fileName = System.IO.Path.GetFileName(postedFile.FileName);
     if(fileName != String.Empty)
     {
      //取得文件的扩展名
      fileExtension = System.IO.Path.GetExtension(fileName);
      //上传的文件信息
      strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
      strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
      strMsg.Append("上传文件的文件名:" + fileName + "<br>");
      strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr color=red>");
      //保存到指定的文件夹
      postedFile.SaveAs(Server.MapPath(paths) + fileName);
     }
    }
    strStatus.Text = strMsg.ToString();
   // return true;
   }
   catch(System.Exception error)
   {
    strStatus.Text = error.Message;
   // return false;

   } 
  }
<script language="JavaScript" type="text/javascript"> function addFileControl() { var str = '
' document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str) } </script>

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很全面的Ace Admin1.3官方文档,包含有最全面的组件及例子,适合急需使用该技术开发的人。 响应式Bootstrap网站后台管理系统模板ace admin,非常不错的轻量级易用的admin后台管理系统,基于Bootstrap3,拥有强大的功能组件以及UI组件,基本能满足后台管理系统的需求,而且能根据不同设备适配显示,而且还有四个主题可以切换。 网页图标全采用FontAwesome,除Bootstrap,jQuery UI使用到的第三方插件有: jQuery 2.0.3 jQuery UI 1.10.3 (Custom Build) Twitter Bootstrap 3.0.0 FontAwesome 3.2.1 Google "Open Sans" Font jQuery Flot Charts 0.8.1 jQuery Sparklines 2.1.2 Easy Pie Chart 1.2.5 jQuery Knob 1.2.0 jQuery Validate 1.11.1 FuelUX 2.3.0 (Spinner & Wizard & Treeview) FullCalendar 1.6.4 jQuery ColorBox 1.4.27 jQuery dataTables 1.9.4 jQuery Chosen 1.0 jQuery Masked Input 1.3.1 jQuery Input Limiter 1.3.1 jQuery AutoSize 1.17.7 Bootstrap Colorpicker Bootstrap Datepicker Bootstrap Timepicker v0.2.3 Bootstrap DateRange Picker 1.2 Bootbox.js 4.0.0 jQuery Gritter 1.7.4 jQuery slimScroll 1.1.1 Spin.js 1.3.0 jQuery UI Touch Punch 0.2.2 Google Code Prettify ExplorerCanvas Mindmup Wysiwyg Editor Toopay Markdown Editor 1.1.4 X-editable 1.4.6 Select2 3.4.2 Bootstrap Tags 2.2.5 jQuery Mobile 1.3.2 (Custom Build) jqGrid 4.5.2 Dropzone.js 3.0 Nestable lists plugin 浏览器兼容: Firefox 5+ Google Chrome 14+ Internet Explorer 8 Internet Explorer 9 Opera 11 Safari 5 Bootstrap兼容: Bootstrap 2.2.x Bootstrap 2.3.x Bootstrap 3.0.x ace admin

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值