0
public ActionResult SaveFile()
    {
        var uniqueName = "";
        var file = Request.Form.Files["myfile"];
        if (Request.Form.Files["myfile"] != null)
        {
            if (file.FileName != "")
            {
                var ext = System.IO.Path.GetExtension(file.FileName);
                uniqueName = Guid.NewGuid().ToString() + ext;
                string fileSavePath = Path.Combine(V, uniqueName);
                file.SaveAs(fileSavePath);
            }
        }
        //...
        return Json(data, new Newtonsoft.Json.JsonSerializerSettings());
    }

Initially the line of code var file = Request.Form.Files["myfile"]; was written as var file = Request.Files["myfile"]; in the ASP.Net MVC. After I converted it to Form.Files[] for the ASP.Net Core MVC, reference of the .SaveAs got missed up.

Can you help how can we achieve this? Do we need to change the line var file = Request.Form.Files["myfile"]; or Is there any other built-in function for the .SaveAs other than this?

0 Answers0