Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to upload 25 image files to my site named serially from ileUpload1 to ileUpload25 . i wnt to avoid writing code for each file upload separately. kindly help me wit code

What I have tried:

for (int i = 1; i < 25; i++ )
            {
                FileUpload f = new FileUpload();
                f = "FileUpload" + i.ToString();
                string filename = Path.GetFileNameWithoutExtension(f.PostedFile.FileName);
                string fileextension = Path.GetExtension(FileUpload1.PostedFile.FileName);
                FileUpload1.SaveAs(Server.MapPath("~/PhotoGallery/" + filename + fileextension));
            }

but i get the error:
Error Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.FileUpload'
Posted
Updated 25-Feb-21 14:30pm
v2
Comments
[no name] 25-Feb-21 14:12pm    
You're contradicting yourself: i wnt to avoid writing code or each file upload separately. kindly help me wit code
Member 10235977 25-Feb-21 20:35pm    
what i meant was i want to avoid writing code for each file upload separately. i can upload files by repeating the code 25 times - once or each upload. what i want is a code that will repeat itself 25 times for i=1 to i=25.
[no name] 26-Feb-21 11:55am    
If they were all in the same folder / directory, then you could just upload the contents using Directory.GetFiles to get the file names. Alternatively zip the folder, upload, unzip. The list goes on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900