.net multiple file upload

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>
View Code

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);
                }
            }
        }
View Code

This is my solution

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324712737&siteId=291194637