Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 782
  • 1.1k
  • 55.7k

C# home controller image upload query isn't working

Jan 22 2024 8:39 AM
public ActionResult FileUpload()
{
    string relativePath = string.Empty;
    if (file != null)
    {
        // string ImageUniqueName = Guid.NewGuid().ToString();
        //string ActualImageName = ImageUniqueName + Path.GetFileName(file.FileName);
        string pic = System.IO.Path.GetFileName(file.FileName);
        path = System.IO.Path.Combine(Server.MapPath("/images/profile"), pic);
        // file is uploaded
        file.SaveAs(path);
        relativePath = Path.Combine("/images/profile", ActualImageName);
    }
    return Json(relativePath, JsonRequestBehavior.AllowGet);
}

 


Answers (4)