ASP.NET save files from dynamically added FileUpload controls
<p>I'm building an ASP.NET UserControl where users of the website can upload several pictures at once. I'm doing it the old fashioned way by letting the user enter the amount of FileUpload controls wanted and then add them dynamically from C# to a asp:Panel control. </p>

<p>While this works, the values/files from the FileUpload isn't stored for when the user clicks the "Save" button. How exactly do I go about this problem?</p>

<p>My code for specifying the amount of FileUpload controls wanted:</p>

<pre><code>protected void btnSubmitImageAmount_Click(object sender, EventArgs e)
{
    int amountOfControls = Convert.ToInt32(txtImageAmount.Text);

    for (int i = 0; i &lt; amountOfControls; i++)
    {
        FileUpload fUl = new FileUpload();
        Label lblLineBreak = new Label();
        lblLineBreak.Text = "&lt;br /&gt;";
        fUl.ID = i.ToString();
        fUl.Visible = true;
        pnlUploadControls.Controls.Add(fUl);
        pnlUploadControls.Controls.Add(lblLineBreak);
    }
}
</code></pre>

<p>Code for the Save button:</p>

<pre><code>protected void btnCreateStory_Click(object sender, EventArgs e)
{
    List&lt;Media&gt; images = new List&lt;Media&gt;();

    foreach (Control ctrl in pnlUploadControls.Controls)
    {
        if (ctrl is FileUpload)
        {
           FileUpload fUl = (FileUpload)ctrl;
           Media media = UmbracoSave(fUl, storydDoc.Id);
           if (media != null)
           {
               images.Add(media);
           }
        }
    }
}
</code></pre>

<p>Anyone got any hints of how to solve this problem? :)</p>

<p>Thanks in advance!</p>
