I have hosted in a shared windows server, I want to save images on the server, and update its path in the database. When I update the path in the database it is looking like something mentioned below,
C:\ClientSites\mydomain.com\mydomain.com\pictures\20210330160946.png
How can I save with the correct URL so that I can use the complete URL for images to display?
var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), @_configuration.GetSection("pictures").Value);
var file = Request.Form.Files[0];
if (file.Length > 0)
{
var user = dbContext.User.GetById(1000);
var fileName = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}{Path.GetExtension(file.FileName)}";
var fullPath = Path.Combine(pathToSave, fileName);
using (var stream = new FileStream(fullPath, FileMode.Create))
{
file.CopyTo(stream);
}
user.ProfilePhotoUrl = fullPath;
var result = dbContext.User.Update(user);
if (result.Succeeded)
{
return Json(fullPath);
}
}