public void addProduct(string productname, string gender, string productFamilyId, string productdescription, string price, string quantity, string size, string color, string visibility, string productCat_Sub_ID, string brandID, string collection, string images, string email, string clientID, string fileNames1, string ecommecelink, string productSKU, string masterPwd) { try { MySQLBusinessLogic bl = new MySQLBusinessLogic(); DataTable dt = bl.GetStoreID(email); int storeID = Convert.ToInt32(dt.Rows[0].ItemArray[0]); int productCategoryID = Convert.ToInt32(productCat_Sub_ID.Split('_')[1]); int productSubCategoryID = Convert.ToInt32(productCat_Sub_ID.Split('_')[0]); List<string> lstImgID = new List<string>(); List<string> lstImgPath = new List<string>(); List<string> lstImgOrgPath = new List<string>(); var fileNames = fileNames1.Split(','); var fileimages = images.Split(','); byte[] PrvImg = null; List<byte[]> lstByte = new List<byte[]>(); string rootPath = System.Configuration.ConfigurationManager.AppSettings.GetValues("RootPath").First().ToString(); string rp = rootPath; rootPath += storeID.ToString() + "\\"; for (int i = 0; i < fileNames.Length; i++) { string fileName = fileNames[i]; string encodedFileName = fileimages[i]; if (fileName != encodedFileName) { fileName = Regex.Replace(fileName.Substring(0, fileName.LastIndexOf('.')), "[.;]", "_") + fileName.Substring(fileName.LastIndexOf('.'), (fileName.Length - fileName.LastIndexOf('.'))); if (File.Exists(rp + fileName)) File.Delete(rp + fileName); System.IO.File.Move(rp + encodedFileName, rootPath + fileName); //if (i == 0) //{ // Image image = Image.FromFile(rootPath + fileName); // Image thumb = image.GetThumbnailImage(100, 100, () => false, IntPtr.Zero); // thumb.Save(Path.ChangeExtension(rootPath + fileName.Split('.')[0], "thumb")); // System.IO.File.Move(rootPath + fileName.Split('.')[0] + ".thumb", rootPath + "Thumb" + fileName); // FileStream fs1 = new FileStream(rootPath + "Thumb" + fileName, FileMode.Open, FileAccess.Read); // BinaryReader br1 = new BinaryReader(fs1); // PrvImg = br1.ReadBytes((int)fs1.Length); // br1.Close(); // fs1.Close(); //// File.Delete(rootPath + "Thumb" + fileName); //} } //test image save code string FileName = rootPath + fileName; byte[] ImageData; FileStream fs = new FileStream(rootPath + fileName, FileMode.Open, FileAccess.Read); using (var image1 = Image.FromStream(fs)) { var newWidth = (int)(image1.Width * 0.9); var newHeight = (int)(image1.Height * 0.9); var thumbnailImg = new Bitmap(newWidth, newHeight); var thumbGraph = Graphics.FromImage(thumbnailImg); thumbGraph.CompositingQuality = CompositingQuality.HighQuality; thumbGraph.SmoothingMode = SmoothingMode.HighQuality; thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic; var imageRectangle = new Rectangle(0, 0, newWidth, newHeight); thumbGraph.DrawImage(image1, imageRectangle); thumbnailImg.Save(rootPath + "New" + fileName, image1.RawFormat); FileStream fs2 = new FileStream(rootPath + "New" + fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs2); ImageData = br.ReadBytes((int)fs2.Length); br.Close(); fs2.Close(); } fs.Close(); //Image image1 = Image.FromFile(rootPath + fileName); //Image thumb1 = image1.GetThumbnailImage(image1.Width, image1.Height, () => false, IntPtr.Zero); //thumb1.Save(Path.ChangeExtension(rootPath + fileName.Split('.')[0], "thumb")); //System.IO.File.Move(rootPath + fileName.Split('.')[0] + ".thumb", rootPath + "New" + fileName); //FileStream fs = new FileStream(rootPath + "New" + fileName, FileMode.Open, FileAccess.Read); //BinaryReader br = new BinaryReader(fs); //ImageData = br.ReadBytes((int)fs.Length); //br.Close(); //fs.Close(); //File.Delete(rootPath + "New" + fileName); lstImgPath.Add(rootPath + "New" + fileName); lstImgOrgPath.Add(rootPath + fileName); lstImgID.Add("image" + (i + 1)); //File.Delete(rootPath + fileName); if (ImageData.Length < 16777216) lstByte.Add(ImageData); } //int brandID = 0; //brandID = bl.GetBrandNameID(brand); //if (brandID == 0) //{ // brandID = bl.InsertBrandandGetID(brand); //} int retVal = bl.AddProduct(productname, gender, Convert.ToInt32(productFamilyId), productdescription, Convert.ToDouble(price), quantity, size, color, Convert.ToInt32(visibility), productCategoryID, productSubCategoryID, Convert.ToInt32(brandID), collection, images, storeID, DateTime.Now, email, lstByte, PrvImg, ecommecelink, productSKU, masterPwd,lstImgID,lstImgPath,lstImgOrgPath); if (size != "" || color != "" || collection != "") { bl.AddSpecification(email, color, size, collection); } if (retVal == 1) Clients.Client(clientID).addedProduct("1"); else Clients.Client(clientID).addedProduct("0"); } catch (Exception ex) { Clients.Client(clientID).addedProduct("0"); } }