How to create single fileUpload using MVC 4?

How to create single fileUpload using MVC 4?, someone asked me to explain?

To begin create an mvc project called mvc-tutorials and also create a class and name it as picture with a single propery file with datatype HttpPostedFileBase.

Step 1: Create a class and give a name picture.Copy and paste the following code.

public class picture {
    public HttpPostedFileBase file { get; set; }

Step 2: Right click on the "Controllers" folder and add "fileUpload" controller. Copy and paste the following code.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVC_tutorials.Controllers
    public class fileUploadController : Controller
        // GET: /fileUpload/
        public ActionResult Index()
            return View();
        public ActionResult Index(picturepicture)
            if (picture.file.ContentLength > 0) {
                var fileName = Path.GetFileName(picture.file.FileName);
                var filePath = Path.Combine(Server.MapPath("~/Images"), fileName);
            return RedirectToAction("Index");

Step 3: Right click on the "Index" action method in the "fileUploaderController" and add "Index" view. Copy and paste the following code.

    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width" />
    <title>single fileupload in MVC</title>
    <style type="text/css">
        .btn {
            width: 100px;
            height: 50px;
            background: #00BCD4;
            border-style: solid;
            border-color: white;
            color: white;
<body style="border: 1px solid #DED8D8; width: 400px; font-family: Arial; margin-left: 50px">
    @using (@Html.BeginForm(null, null, FormMethod.Post,
     new { enctype = "multipart/form-data" }))
                <td style="padding-bottom: 35px" colspan="2">
                   <h2 style="color: #FF5722">single file upload in</h2>
                <td style="width: 100px;">
                   <b style="color: #FF5722">File:</b>
                   <input type="file" name="file" id="file" />
                <td colspan="2" style="padding-top: 30px">
                   <input type="submit" class="btn" name="submit" />


create single fileUpload using MVC 4

Post your comments / questions