5

I'm getting an error on HttpPostedFileBase:

The type or namespace name 'HttpPostedFileBase'could not be found(are you missing a using directive or an assembly reference?)

I have already tried to use using System.Web but didn't work at all.

Edit #1

public IActionResult Upload(HttpPostedFileBase file)
    {

        if (file.contentlength > 0)
        {
            var filename = Path.GetFileName(file.filename);
            var path = Path.Combine(Server.mappath("~/app_data/uploads"), filename);
            file.saveas(path);
        }

        return RedirectToAction("index");
    }

I dont acctually have a reference folder No references folder

Dorin Munteanu
  • 93
  • 1
  • 1
  • 10

2 Answers2

12

You can't mix and match tutorials and framework versions. You're on ASP.NET Core 2.0.8, which doesn't contain HttpPostedFileBase.

The ASP.NET Core counterpart of HttpPostedFileBase is IFormFile.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
1

For ASP.NET CORE

Check this post.

For ASP.NET MVC

1. Add reference for System.Web DLL in your project.

2. Using using directive add using System.Web statement on top of your .cs file.

enter image description here

For more check this post.

Shaiju T
  • 6,201
  • 20
  • 104
  • 196
  • on my reference tab I can only add reference to my project pages... https://imgur.com/a/y8WBGah – Dorin Munteanu Jun 18 '18 at 11:17
  • @DorinMunteanu , I have added screen shot please check, I mean , expand and check your references in your solution explorer for `System.Web` DLL , if you find it missing , just add it. – Shaiju T Jun 18 '18 at 11:26
  • @DorinMunteanu , add that image in your question so others can help. – Shaiju T Jun 18 '18 at 11:34
  • @DorinMunteanu , Don't just add the image link, edit and attach that screen shot in your question so others can help. – Shaiju T Jun 18 '18 at 11:37
  • Please mention tag as asp.net core , to get answers soon. @CodeCaster is correct one. – Shaiju T Jun 18 '18 at 11:45
  • This is for ASP.NET Core. There is no `System.Web`, and it would be absolutely wrong to try to manually reference the DLL. – Chris Pratt Jun 18 '18 at 12:47
  • @ChrisPratt , you are correct, initially the OP had `asp.net mvc` tag added , so I though OP is after `asp.net mvc` solution. I have updated the answer to `asp.net core` and `asp.net mvc` , it may help others. – Shaiju T Jun 19 '18 at 04:52