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.
I'm sure there's a way to do this that I'm just not thinking of - TIA!
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
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
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="padding:13px">
<asp:Button ID="btnAdd" runat="server" Text="Add FileUpload Control" OnClick="btnAdd_Click" />
<br /><br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />
<br /><br />
<asp:Button ID="btnUploadFile" runat="server" Text="Upload File(s)" OnClick="btnUploadFile_Click" />
</div>
</form>
</body>
</html>