public async Task<IActionResult> OnPostAsync()
{
if (ModelState.IsValid)
{
if (Image != null)
{
var fileContent = ContentDispositionHeaderValue.Parse(Image.ContentD isposition);
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = GetUniqueName(Path.GetFileName(fileContent.FileNam e.ToString().Trim('"')));
//The below line gives the error
//var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, "App_Data", fileName);
//and I replace with this (but we can use this variable at multiple location by assign a physical path)
// var physicalPath = Path.Combine(Path.Combine(Directory.GetCurrentDire ctory(), "wwwroot"), "Images", fileName);
var physicalPath = $"{Directory.GetCurrentDirectory()}{@"wwwrootima ges"+ fileName}";
//The files are not actually saved in this demo
using (var fileStream = new FileStream(physicalPath, FileMode.Create))
{
await Image.CopyToAsync(fileStream);
}
string link = physicalPath;
Phone.Photo = link.ToString();
phones.Insert(this.Phone.Name, this.Phone.Last, this.Phone.Photo, this.Phone.Email, this.Phone.Mobile);
}
}
return Page();
}
برچسب:
نویسنده: خنج