public ActionResult ProfilPicture(int userId, HttpPostedFileBase pic) { if (Session["UserName"] == null) { return(RedirectToAction("Error")); } if (pic != null && pic.ContentLength > 0) { var fileName = Path.GetFileName(pic.FileName); List <string> imgExtension = new List <string>(new string[] { ".gif", ".png", ".PNG", ".jpg", ".jpeg", ".bmp", ".tiff" }); string extension = Path.GetExtension(fileName); if (imgExtension.Contains(extension)) { var path = Path.Combine(Server.MapPath("~/Content/images/profil"), userId.ToString() + fileName); if (!System.IO.File.Exists(fileName)) { pic.SaveAs(path); } string profilPicUrl = "~/Content/images/profil/" + userId.ToString() + Path.GetFileName(pic.FileName); Session["UserPic"] = profilPicUrl; KoombuBll kBll = new KoombuBll(); kBll.AddProfilPic(userId, profilPicUrl); } } return(RedirectToAction("Profil", new { id = userId })); }