I'm trying to upload multiple files using
<input id="testUpload" type="file" multiple="true"/>
(yes, i know it doesn't work on IE). But my question is what should i do after that in the code to iterate through each file and upload it ?
I'm trying
foreach(HttpPostedFile file in Request.Files["testUpload"]){
}
But i get
foreach statement cannot operate on variables of type 'System.Web.HttpPostedFile' because 'System.Web.HttpPostedFile' does not contain a public definition for 'GetEnumerator'
I know i can just do for multiple = "false" :
HttpPostedFile file = Request.Files["testUpload"];
And then do operation on that file. But what if i'm selecting multiple files ? How to iterate though each one using foreach ?
You are trying to iterate over one file rather than the collection.
Change
foreach(HttpPostedFile file in Request.Files["testUpload"]){
}
to
EDIT - changed to for loop as per comment
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
if(file .ContentLength >0){
//saving code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With