[HttpPost][ValidateAntiForgeryToken]publicasyncTask<IActionResult>Create(Employee emp){if(ModelState.IsValid){var files =HttpContext.Request.Form.Files;foreach(varImagein files){if(Image!=null&&Image.Length>0){var file =Image;//There is an error herevar uploads =Path.Combine(_appEnvironment.WebRootPath,"uploads\\img");if(file.Length>0){var fileName =Guid.NewGuid().ToString().Replace("-","")+Path.GetExtension(file.FileName);using(var fileStream =newFileStream(Path.Combine(uploads, fileName),FileMode.Create)){await file.CopyToAsync(fileStream);
emp.BookPic= fileName;}}}}
_context.Add(emp);await _context.SaveChangesAsync();returnRedirectToAction("Index");}else{var errors =ModelState.Values.SelectMany(v => v.Errors);}returnView(emp);}
when i save image, image save successfully in database, but it takes full image path like this C:\Users\VIZO\Desktop\employee.jpg
i dont want like this, i need to save image path something like this ~images\employee.jpg.
The other problem is image doesnt saving in
specific folder of project, i need to save image in this path of my project
uploads\\img