.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Uploading multiple images in server folder using Asp.net

Posted By:Dhivakaran       Posted Date: November 30, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

In this article I m going to expalin multiple image upload in single button click
 

 

Html code:

 

Image 2
Image 3
Image 4
Image 5

C# Code:

protected void btnUpload_Click(object sender, EventArgs e)
    {
        
     
        HttpFileCollection uploadFilCol = Request.Files;
        for (int i = 0; i < uploadFilCol.Count; i++)
        {
            HttpPostedFile file = uploadFilCol[i];
            string fileExt = Path.GetExtension(file.FileName);
            string fileName = Path.GetFileName(file.FileName);
            if (fileName != string.Empty)
            {
                try
                {
                    if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png" || fileExt == ".JPG" || fileExt == ".GIF" || fileExt == ".PNG" || fileExt == ".bmp" || fileExt == ".BMP")
                    {
                       
                            file.SaveAs(Server.MapPath("./UploadImg/") + fileName + fileExt);
                         this.ShowMessage(" " + fileName + " Successfully Uploaded", i);
                        
                    }
                    

                }
                catch (Exception ex)
                {
                    this.ShowMessage(" " + ex.Message, i);
                }
            }
        }
    }
    private void ShowMessage(string message, int fileUploadPos)
    {
        if (fileUploadPos == 0)
        {
            Label1.Text = message;
        }
        else
        {
            if (fileUploadPos == 1)
            {
               Label2.Text = message;
            }
            else
            {
                Label3.Text = message;
            }
        }
    }

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend