public async Task <IActionResult> SubmitProfile() { try { var httprequest = HttpContext.Request.Form; var obj = httprequest["obj"]; UserRegistration usereg = new UserRegistration(); string fileName = null; var postedfile = httprequest.Files["file"]; usereg.AddBy = httprequest["addBy"].ToInt(); usereg.ContactNo = httprequest["contactNo"].ToStr(); usereg.Email = httprequest["email"].ToStr(); usereg.FullName = httprequest["fullName"].ToStr(); usereg.Password = httprequest["password"].ToStr(); usereg.Address = httprequest["address"].ToStr(); usereg.StateId = httprequest["stateId"].ToInt(); usereg.CompanyName = httprequest["companyName"].ToStr(); usereg.Id = httprequest["id"].ToInt(); usereg.PinCode = httprequest["pinCode"].ToStr(); // Create Custom File Name string filePath = string.Empty; if (postedfile != null) { fileName = new String(Path.GetFileNameWithoutExtension(postedfile.FileName).Take(10).ToArray()).Replace(" ", "-"); fileName = fileName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedfile.FileName); string webRootPath = _hostingEnvironment.WebRootPath; var contentRootPath = _hostingEnvironment.ContentRootPath; //var fileName = Path.GetFileName(postedfile.FileName); filePath = contentRootPath + "\\Documents\\" + fileName; using (var stream = System.IO.File.Create(filePath)) { await postedfile.CopyToAsync(stream); } } usereg.ImageName = fileName; usereg.ImagePath = filePath; var data = await _userregistrationService.SaveProfile(usereg); return(Ok(data)); } catch (Exception Ex) { throw Ex; } }