To get rid of your first error...
Change
foreach (string data in files)
to
foreach (var data in files)
Then hover your mouse over the word
var
- you will see that it is of type
FileUpload
- as Caldazar87 pointed out, the collection is not a collection of string, but a collection of FileUpload.
The second error is probably because you used to have a
for
loop here with an iterator of
i
. You have now replaced that with a
foreach
and
i
no longer exists. You don't need to use
files.ElementAt
as the
data
variable is already giving you that element.
Which leads me to the next issue you have - you are not doing anything with that name - at the very least you appear to want to assign it to a string variable e.g.
var theName = data.Name;
Which will then present you with another problem in the line
str.Add(data);
- you declared
str
as a
List<string></string>
but
data
is a
FileUpload
object. I'm guessing you just want the name of the file so change that part from
files.ElementAt(i).Name;
str.Add(data);
to
str.Add(data.Name);
Finally, make sure that you read the Error List fully when trying to compile your program - all of these errors would be listed and usually there is enough of a clue to point you in the direction of the fix. If you are using Visual Studio, you can double click on a error to take you to the line of code that is at fault. Always start looking at the first error on the list as many of the others may disappear once that is fixed.