JumpStart # 12–Multiple File Upload in ASP.Net 4.5

Before looking at the code, Read about – What is JumpStart?

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        // Check for FileUpload Control got any Files
        if (FileUpload1.HasFiles)
        {
            // Iterate FileUpload Controls Files
            foreach (HttpPostedFile file in FileUpload1.PostedFiles)
                file.SaveAs(Server.MapPath("~/Images/") + file.FileName);
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <!-- Use the Regular FileUpload Control, but with AlloMultiple="true" attribute -->
        <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </div>
    </form>
</body>
</html>

 

Solution Structure –

MultipleFileUpload_pic1

You may also like...