claygarrett
asked on
Looping through HTMLInputFiles
I have HTMLFileInput fields with runat="server" like so:
<INPUT id="file1" type="file" name="file" runat="server">
<INPUT id="file2" type="file" name="file" runat="server">
<INPUT id="file3" type="file" name="file" runat="server">
...etc....
When the button is pressed to save the form/upload the files, I have a pretty lengthy sub that each of these boxes needs to be passed to. Is there a way to do this via a looping structure of some sort, instead of me having to call the function once for each file field?
I want to avoid doing this:
-------------------------- ---------- -------
DoSomethingToMyFile(file1)
DoSomethingToMyFile(file2)
DoSomethingToMyFile(file3)
Function DoSomethingToMyFile(myFile as HTMLInputFile)
End Function
-------------------------- ---------- -------
because the page will have up to 30-40 file fields. I'd rather do something to this effect:
-------------------------- ---------- -------
For i as Integer = 1 to intNumFiles
DoSomethingToMyFile("file" & i)
Next
Function DoSomethingToMyFile(myFile as HTMLInputFile)
End Function
-------------------------- ---------- -------
You used to be able to do this in vbscript with the "Eval" statement - but I know that doesn't really apply in .NET. Any ideas?
Thanks,
Clay
<INPUT id="file1" type="file" name="file" runat="server">
<INPUT id="file2" type="file" name="file" runat="server">
<INPUT id="file3" type="file" name="file" runat="server">
...etc....
When the button is pressed to save the form/upload the files, I have a pretty lengthy sub that each of these boxes needs to be passed to. Is there a way to do this via a looping structure of some sort, instead of me having to call the function once for each file field?
I want to avoid doing this:
--------------------------
DoSomethingToMyFile(file1)
DoSomethingToMyFile(file2)
DoSomethingToMyFile(file3)
Function DoSomethingToMyFile(myFile
End Function
--------------------------
because the page will have up to 30-40 file fields. I'd rather do something to this effect:
--------------------------
For i as Integer = 1 to intNumFiles
DoSomethingToMyFile("file"
Next
Function DoSomethingToMyFile(myFile
End Function
--------------------------
You used to be able to do this in vbscript with the "Eval" statement - but I know that doesn't really apply in .NET. Any ideas?
Thanks,
Clay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.