public async Task <string> UploadImage(IFormFile files) { if (files.Length < 0) { return("Unsuccessful"); } try { string fileName = files.FileName; int fileID = Int32.Parse(Path.GetFileNameWithoutExtension(files.FileName)); string path = UrlHelpers.GetFileStoragePath(fileID, fileName, '\\'); path = Path.Combine(_environment.WebRootPath, _iconfiguration["ImageStore"] + "\\", path); if (!Directory.Exists(path.Replace(fileName, ""))) { Directory.CreateDirectory(path.Replace(fileName, "")); } using (var stream = new FileStream(path, FileMode.Create)) { await files.CopyToAsync(stream); } return("Success"); } catch (Exception ex) { return(ex.ToString()); } }