As soon as you look at HttpFileCollection
's documentation, it becomes clearer...
The indexer has a declared type of HttpPostedFile
. Whereas GetEnumerator
states:
This enumerator returns the keys of the collection as strings.
So basically your foreach
loop is iterating over the keys in the collection, whereas you want the values. This is inherently a weird design decision in NameObjectCollectionBase
.
You could use:
foreach (var file in documentsList.Cast<string>()
.Select(key => documentsList[key]))
{
...
}