I found a solution, but the result I've got is designed in other way, which doesn't use Server controls
of ASP.NET, I handled the plain HTML
elements.
In ASPX page, I defined:
<%
for (int i = 0; i < Helper.uploadFieldsCount; i++)
{
Response.Write("<input type='file' id='uploadField" + i.ToString() + "' name='uploadField" + i.ToString() + "' class='file_1' /><br />");
}
%>
runat
was defined in the main form of the page, in the beginning:
<body>
<form enctype="multipart/form-data" id="form1" runat="server">
...
In the CodeBehind
I'm uploading a new file with randomly generated name based on GUID
:
void buttonUpload_Click(object sender, EventArgs e)
{
List<string> generatedFileNames = new List<string>();
bool wereErrors = false;
for (int i = 0; i < Helper.uploadFieldsCount; i++)
{
HttpPostedFile filePosted = Request.Files["uploadField" + i.ToString()];
if (filePosted != null && filePosted.ContentLength > 0)
{
string fileNameApplication = System.IO.Path.GetFileName(filePosted.FileName);
string fileExtensionApplication = System.IO.Path.GetExtension(fileNameApplication);
string newFile = Guid.NewGuid().ToString() + fileExtensionApplication;
string filePath = System.IO.Path.Combine(Server.MapPath("uploads"), newFile);
if (fileNameApplication != String.Empty)
{
generatedFileNames.Add(newFile);
filePosted.SaveAs(filePath);
}
}
...