public ActionResult UpdateProfilePicture(HttpPostedFileBase profilePicture, string UserId) { try { string filePath = string.Empty; if (profilePicture != null) { string folderpath = Server.MapPath("~/") + "Content/Images"; if (!System.IO.Directory.Exists(folderpath)) { System.IO.Directory.CreateDirectory(folderpath); } string path = Server.MapPath("~/Content/Images/ProfilePictures"); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } Random r = new Random(); int randomNo = r.Next(); filePath = "/Content/Images/ProfilePictures/" + randomNo + "_" + profilePicture.FileName; profilePicture.SaveAs(Server.MapPath("~/Content/Images/ProfilePictures/" + randomNo + "_" + profilePicture.FileName)); _userServiceAgent.UpdateUserProfilePicture(UserId, filePath); SessionHelper.UserImage = filePath; return(Json(new { success = true, filePath = filePath }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, filePath = "" }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new { success = false, filePath = "" }, JsonRequestBehavior.AllowGet)); } }