0

I was trying to have a upload function in my ASP.NET application where users can select a file to upload to a specified server. I came across this answer ...

File Upload ASP.NET MVC 3.0

and used the following code from it...

public ActionResult Index(HttpPostedFileBase file)
        {
            // Verify that the user selected a file
            if (file != null && file.ContentLength > 0)
            {
                // extract only the filename
                var fileName = Path.GetFileName(file.FileName);
                // store the file inside ~/App_Data/uploads folder
                var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                file.SaveAs(path);
            }
            // redirect back to the index action to show the form once again
            return RedirectToAction("Index");
        }

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="file" />
    <input type="submit" value="OK" />
}

However it keeps telling me HttpPostedFileBase and "Server" does not exist in the current context even though I have the System.Web import

Renji
  • 43
  • 1
  • 7
  • Have you tried `System.Web.HttpPostedFileBase` instead of `HttpPostedFileBase` ? – AlexB Sep 07 '18 at 14:40
  • @AlexB yeah i've tried this and it doesn't work – Renji Sep 07 '18 at 14:42
  • Have you referenced these 2 assemblies: `System.Web` and `System.Web.Abstractions`? The namespace can span inside multiple assemblies, make sure you put all of them. – Tetsuya Yamamoto Sep 08 '18 at 00:24
  • @TetsuyaYamamoto System.Web.Abstractions isn't even an import that I can use it seems, not sure what my project is missing here – Renji Sep 10 '18 at 09:28

0 Answers0