Click here to Skip to main content
15,888,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
I want to upload multiple files with fileupload. That works :) But it should upload multiple files with a Limit of 5 files. 

Here is my behind code:


C#
protected void btnUpload_Click(object sender, EventArgs e)
        {

            StartUpLoad();
        }

        private void StartUpLoad()
        {
            string imgName = FileUpload1.FileName;
            string imgPath = "~/Uploads/" + imgName;
            int imgSize = FileUpload1.PostedFile.ContentLength;
            string ext = System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName);
            if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
            {
                if (ext.ToUpper().Trim() != ".JPG" && ext.ToUpper() != ".PNG" && ext.ToUpper() != ".GIF" && ext.ToUpper() != ".JPEG")
                {
                    Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Only .jpg, .png oder .gif!')", true);
                }

                else
                {

                    FileUpload1.SaveAs(Server.MapPath("~/Uploads/") + FileUpload1.FileName);
                    Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Saved!')", true);

                }
            }
        }


What I have tried:

I think, that there should be something with count...but I am not sure.....
Posted
Updated 3-Nov-16 6:59am
Comments
Are you sure this code uploads multiple files?
PeejayAdams 3-Nov-16 13:03pm    
You need to loop through PostedFiles (plural) rather than looking at PostedFile (singular).

1 solution

Refer - Upload multiple files with ASP.Net 4.5 FileUpload control in Visual Studio 2012 and 2013[^].

FileUpload.PostedFiles would give you a Count method to count the number of files.
 
Share this answer
 

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