Monday, August 1, 2016

Multiple File Upload in asp.net

Default.aspx

<div>
        <input type="file" id="FileUpload" multiple="multiple" runat="server" />
        <asp:Button runat="server" ID="btnupload" Text="Upload" OnClick="btnupload_Click" />&nbsp;<br/>
        <asp:Label runat="server" ID="lblName"></asp:Label>
    </div>


Default.aspx.cs

protected void btnupload_Click(object sender, EventArgs e)
        {        
            string savepath = Server.MapPath("foldername");
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFile hpf = Request.Files[i];
                string filename = hpf.FileName;            
                hpf.SaveAs(savepath + @"\" + filename);
            }
        } 

No comments: