public ActionResult Remove(int id) { try { ApplicationDAO dao = new ApplicationDAO(); ImageDAO idao = new ImageDAO(); Application a = dao.SearchById(id); if (Session["ModId"] != null || int.Parse(Session["DevId"].ToString()) == a.DeveloperId) { try { IList <Image> imgs = idao.SearchAppImages(a.Id); foreach (var i in imgs) { string p = i.Url; p = p.Replace("../../..", "../.."); string fullPath = Request.MapPath(p); idao.Remove(i); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } } catch { } try { string pa = a.Archive; pa = pa.Replace("../../..", "../.."); string fullPathArch = Request.MapPath(pa); if (System.IO.File.Exists(fullPathArch)) { System.IO.File.Delete(fullPathArch); } } catch { } dao.Remove(a); return(RedirectToAction("Summary", "Developer")); } return(RedirectToAction("Index", "Home")); } catch { return(RedirectToAction("Index", "Home")); } }