Hi :)
I'm trying to upload multiple images and resize them before upload!
I use this code But it's resize and save just the firs selected image!
for example if 2 image selected , the first one resize and upload twice!
thanks for any Help!
protected void uploadFile_Click(object sender, EventArgs e) { // Check file exist or not if (UploadImages.PostedFile != null) { // Check the extension of image string extension = Path.GetExtension(UploadImages.FileName); if (extension.ToLower() == ".png" || extension.ToLower() == ".jpg") { int name = 101101; int count = 1; foreach (HttpPostedFile postedfile in UploadImages.PostedFiles) { Stream strm = UploadImages.PostedFile.InputStream; var image = System.Drawing.Image.FromStream(strm); string imgName = Convert.ToString(name) + "_" + Convert.ToString(count); // Print Original Size of file (Height or Width) Label1.Text = image.Size.ToString(); int newWidth = image.Width / 2; // New Width of Image in Pixel int newHeight = image.Height / 2; // New Height of Image in Pixel var thumbImg = new Bitmap(newWidth, newHeight); var thumbGraph = Graphics.FromImage(thumbImg); thumbGraph.CompositingQuality = CompositingQuality.HighSpeed; thumbGraph.SmoothingMode = SmoothingMode.HighSpeed; thumbGraph.InterpolationMode = InterpolationMode.Low; var imgRectangle = new Rectangle(0, 0, newWidth, newHeight); thumbGraph.DrawImage(image, imgRectangle); // Save the file string targetPath = Server.MapPath(@"~\Images\") + imgName + ".jpg"; thumbImg.Save(targetPath, image.RawFormat); count++; } } } }