I have to be upload 4-5 image, and have to upload all them , if size is larger then I have to crop all then then save details in db.if I have to upload one image and crop then its fine but getting issue with more than one Image.
- public void ProcessRequest(HttpContext context)
- {
- Boolean FileOK = false;
- Boolean SizeOK = false;
- try
- {
- if (context.Request.Files.Count > 0)
- {
- BEL_Package objBel = new BEL_Package();
- string Output = string.Empty;
- HttpFileCollection files = context.Request.Files;
- for (int i = 0; i < files.Count; i++)
- {
- HttpPostedFile file = files[i];
- string sImageName = file.FileName;
- file.SaveAs(HttpContext.Current.Server.MapPath("~/" + Path.GetFileName(file.FileName)));
- System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(HttpContext.Current.Server.MapPath("~/" + Path.GetFileName(file.FileName)));
- int iwidth = bitmap.Width;
- int iheight = bitmap.Height;
- bitmap.Dispose();
-
-
- Width: " + iwidth + ", Height: " + iheight +
-
- " + hpf.ContentLength / 1024 + " KB
- ";
-
-
-
- System.Drawing.Image objOptImage = new System.Drawing.Bitmap(iwidth, iheight, System.Drawing.Imaging.
- PixelFormat.Format16bppRgb555);
-
- using (System.Drawing.Image objImg =
- System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("~/" + sImageName)))
- {
-
- using (System.Drawing.Graphics oGraphic = System.Drawing.Graphics.FromImage(objOptImage))
- {
- var _1 = oGraphic;
- System.Drawing.Rectangle oRectangle = new System.Drawing.Rectangle(0, 0, iwidth, iheight);
- _1.DrawImage(objImg, oRectangle);
- }
-
- objOptImage.Save(HttpContext.Current.Server.MapPath("~/images/" + sImageName), System.Drawing.Imaging.ImageFormat.Png);
- objImg.Dispose();
- }
- objOptImage.Dispose();
-
- System.Drawing.Bitmap bitmap_Opt = new System.Drawing.Bitmap(HttpContext.Current.Server.MapPath("~/images/" + Path.GetFileName(sImageName)));
- int iwidth_Opt = bitmap_Opt.Width;
- int iheight_Opt = bitmap_Opt.Height;
- bitmap_Opt.Dispose();
-
- FileInfo OptImgInfo = new FileInfo(HttpContext.Current.Server.MapPath("~/images/" + Path.GetFileName(sImageName)));
- long lFileSize = OptImgInfo.Length;
- string fname;
- if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
- {
- string[] testfiles = file.FileName.Split(new char[] { '\\' });
- fname = testfiles[testfiles.Length - 1];
- }
- else
- {
- fname = file.FileName;
- }
- string path = context.Server.MapPath("~/Admin/AllPackageImages/");
- fname = Path.Combine(path, fname);
- string PackageId = HttpContext.Current.Request.Form["PackageId"];
- int j;
- bool result = int.TryParse(PackageId, out j);
- if (result == false)
- {
- j = GeticonsId(PackageId);
- }
- else
- {
- j = Convert.ToInt32(PackageId);
- }
- objBel.filename = file.FileName; ;
- objBel.P_ID_N = Convert.ToInt32(j);
- objBel.Mode = "InsertBanner";
- objBel.R_ID_N = i;
- BAL_PackageINBandInternational objBalII = new BAL_PackageINBandInternational();
- Output = objBalII.Insert_BannerImages(objBel);
- if (Output.ToLower().Contains("successfully"))
- {
- file.SaveAs(fname);
- context.Response.ContentType = "text/plain";
- context.Response.Write("File Uploaded Successfully!");
- }
- else
- {
- context.Response.ContentType = "text/plain";
- context.Response.Write("Something wrong happened . Pleasde try again!");
- break;
- }
- }
- HttpContext.Current.Response.Redirect("Admin/CropUserProfile.aspx");
- }
- }
- catch (Exception ex)
- {
- context.Response.ContentType = "text/plain";
- context.Response.Write("Something wrong happened . Please try again!");
- }
- }