public ActionResult SaveCategorypic() { // Checking no of files injected in Request object if (Request.Files.Count > 0) { try { // Get all files from Request object HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { //string path = AppDomain.CurrentDomain.BaseDirectory + "Uploads/"; //string filename = Path.GetFileName(Request.Files[i].FileName); HttpPostedFileBase file = files[i]; string fname; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = file.FileName; } int Id = Convert.ToInt16(TempData["Id"]); string filenameee = Id.ToString() + "_" + fname; // Get the complete folder path and store the file inside it. fname = Path.Combine(Server.MapPath("~/images/categoryeventimage/"), filenameee); file.SaveAs(fname); int CId = Convert.ToInt16(TempData["CId"]); CategoryImageEvent CM = new CategoryImageEvent(); CM.Image = filenameee; CM.Id = Id; CM.CategoryId = CId; var obj = MS.SaveEventCategoryimage(CM); } // Returns message that successfully uploaded return(Json("File Uploaded Successfully!")); } catch (Exception ex) { return(Json("Error occurred. Error details: " + ex.Message)); } } else { return(Json("No files selected.")); } }