protected void grdAllCars_RowDeleting(object sender, GridViewDeleteEventArgs e) { var dataKey = grdAllCars.DataKeys[e.RowIndex]; var companyId = Utilities.GetCompanyId(); if (dataKey != null && companyId != null) { decimal cId = Convert.ToDecimal(companyId); decimal CarId = Convert.ToDecimal(dataKey.Value.ToString()); var objContext = new CarShowRoomEntities(); var showRoomData = objContext.tbl_Cars.SingleOrDefault(car => (car.CarId == CarId && car.CompanyId == cId)); var allImages = objContext.tbl_Car_Image.Where(image => image.CarId == CarId).ToList(); var largeImagePaths = new List(); // Complete paths for all full images to be deleted var thmbImagePaths = new List(); // Complete paths for all thumbnail images to be deleted foreach (var img in allImages) { largeImagePaths.Add(img.CarImagePath); thmbImagePaths.Add(img.CarThmb_ImagePath); objContext.DeleteObject(img); } objContext.DeleteObject(showRoomData); objContext.SaveChanges(); try { foreach (var thmbImagePath in thmbImagePaths) { var fi = new FileInfo(Server.MapPath(thmbImagePath)); if (fi.Exists) { fi.Delete(); } } foreach (var largeImagePath in largeImagePaths) { var fi = new FileInfo(Server.MapPath(largeImagePath)); if (fi.Exists) { fi.Delete(); } } } catch { } if (ViewState["SearchQuery"] != null) PopulateGridViewBasedOnQuery(ViewState["SearchQuery"].ToString()); else PopulateGridViewBasedOnQuery(); } }
<identity impersonate="true"> userName="domain\user" password="password" /></identity>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)