Due to the needs of the project, the multi-file upload function is required in the research and development. I also found many solutions on the Internet and tried it myself. The following method is simpler
The first is the front-end code, a client-side file control, plus the multiple="multiple" attribute can select multiple files, and add runat="server"
<form id="form1" runat="server"> <div> <div style="margin-left:100px;margin-top:100px;"> <span>上传文件:</span> <input type="file" id="files" name="files" multiple="multiple" runat="server" /> <asp:Button ID="btnsavefiles" runat="server" Text="上传" OnClick="btnsavefiles_Click" /> </div> </div> </form>
The following is the display effect
Click the upload button to trigger the upload event
protected void btnsavefiles_Click(object sender, EventArgs e) { string files = ""; string sql = ""; for (int i = 0; i < Request.Files.Count; i++) { if (Request.Files[i].ContentLength > 0) { string filename = System.IO.Path.GetFileName(Request.Files[i].FileName); string path = Server.MapPath("/Upload/Files/"); Request.Files[i].SaveAs(path + filename); } } }
This is my solution