Source code location: ./fileupload/fileuploadtest.aspx

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>File upload test</title>
</head>
<body>

<form id="form1" runat="server" enctype="multipart/form-data">
<p id="upload-area">
   <input type="file" runat="server" size="60" />
</p>

<p><a href="#" onclick="addFileUploadBox(); return false;">Add file</a></p>

<p><asp:Button ID="btnSubmit" runat="server" Text="Upload" OnClick="btnSubmit_Click" /></p>

<script type="text/javascript">
function addFileUploadBox()
{
    if (!document.getElementById || !document.createElement)
        return false;
		
    var uploadArea = document.getElementById ("upload-area");
	
    if (!uploadArea)
        return;

    var newLine = document.createElement ("br");
    uploadArea.appendChild (newLine);
	
    var newUploadBox = document.createElement ("input");
	
    // Set up the new input for file uploads
    newUploadBox.type = "file";
    newUploadBox.size = "60";
	
    // The new box needs a name and an ID
    if (!addFileUploadBox.lastAssignedId)
        addFileUploadBox.lastAssignedId = 100;
	    
    newUploadBox.setAttribute ("id", "dynamic" + addFileUploadBox.lastAssignedId);
    newUploadBox.setAttribute ("name", "dynamic:" + addFileUploadBox.lastAssignedId);
    uploadArea.appendChild (newUploadBox);
    
    addFileUploadBox.lastAssignedId++;
}
</script>

<script type="text/C#" runat="server">
void btnSubmit_Click(object sender, EventArgs e)
{
    HttpFileCollection uploads = HttpContext.Current.Request.Files;

    for (int i = 0; i < uploads.Count; i++)
    {
        HttpPostedFile upload = uploads[i];

        if (upload.ContentLength == 0)
            continue;

        // ---------------------------------------------------
        // Save the uploaded file on disk or in database
        // ---------------------------------------------------
    }
}
</script>

</form>
</body>
</html>