1、需求实现word批量上传。
2、使用插件jquery-form.js
3、html代码
注意 multiple="multiple"
1 <form id="frm_upload" method="post" enctype="multipart/form-data"> 2 <input type="file" id="filepath" multiple="multiple" name="file" style="width: 60px; cursor: pointer" accept="application/msword" /> 3 </form>
4、js代码
1 $("#frm_upload").ajaxSubmit({ 2 url: "Public/UploadAttachZD", 3 type: "post", 4 success: function (ort) { 5 } 6 });
5、后台代码
1 string uploadroot = Server.MapPath("~/upload") + "\\11"; 2 if (!Directory.Exists(uploadroot)) 3 Directory.CreateDirectory(uploadroot); 4 var files = Request.Files; 5 if (files.Count != 0) 6 { 7 for (int i = 0; i < files.Count; i++) 8 { 9 var pf = files[i]; 10 int npos = pf.FileName.LastIndexOf('.'); 11 string fileext = ""; 12 if (npos != -1) 13 { 14 fileext = pf.FileName.Substring(npos + 1); 15 } 16 string newfilepath = DateTime.Now.Ticks.ToString().ToLower() + "." + fileext; 17 pf.SaveAs(uploadroot + "\\" + newfilepath); 18 } 19 }