Dorin Munteanu
Dorin Munteanu

Reputation: 103

HttpPostedFileBase missing reference

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

Upvotes: 6

Views: 22577

Answers (2)

Shaiju T
Shaiju T

Reputation: 6607

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.

Upvotes: 1

CodeCaster
CodeCaster

Reputation: 151674

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.

Upvotes: 13

Related Questions