Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I upload a file from a dynamically created FileUpload control with ASP.NET?
    primarykey
    data
    text
    <p>In my code attached below, I'm trying to upload a file via ASP.NET. I am dynamically creating the FileUpload control so that means it's not in my ViewState which (I think) means I can't use the control for uploading files unless I use the old fashioned multipat/form-data way which I don't want to do. I need to be able to allow the user to create multiple FileUpload fields and then when they click the Upload File(s) button, it loops through all the FileUpload fields and uploads them to the server.</p> <p>I'm sure there's a way to do this that I'm just not thinking of - TIA!</p> <pre><code>&lt;%@ Page Language="VB" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;script runat="server"&gt; Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim fup As New FileUpload() fup.ID = "FileUpload1" PlaceHolder1.Controls.Add(fup) End Sub Protected Sub btnUploadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' HOW DO I GET THE FILE THAT WAS SELECTED IN THE DYNAMICALLY CREATE FILEUPLOAD CONTROL? End Sub &lt;/script&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div style="padding:13px"&gt; &lt;asp:Button ID="btnAdd" runat="server" Text="Add FileUpload Control" OnClick="btnAdd_Click" /&gt; &lt;br /&gt;&lt;br /&gt; &lt;asp:PlaceHolder ID="PlaceHolder1" runat="server" /&gt; &lt;br /&gt;&lt;br /&gt; &lt;asp:Button ID="btnUploadFile" runat="server" Text="Upload File(s)" OnClick="btnUploadFile_Click" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload