---
title: "FileUpload in ASP.NET MVC"  
description: "In this I article I will explain how to upload file from the client computer to the server.  Open studio 2010 and create a new ASP.NET MVC 3 Web Appli"  
author: "Chris Anderson"  
published: 2011-10-10  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/772/fileupload-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# FileUpload in ASP.NET MVC

In this I [article](https://yourviews.mindstick.com/view/81489/kashmir-now-after-an-year-of-abrogation-of-article-370) I will [explain](https://www.mindstick.com/forum/159699/what-is-a-compilation-error-in-dot-net-core-explain-with-an-example) how to upload file from the client computer to the server.\

Open studio 2010 and create a new [ASP.NET MVC](https://www.mindstick.com/articles/1571/start-with-asp-dot-net-mvc-4) 3 [Web Application](https://www.mindstick.com/articles/13069/progressive-web-application-pwas-all-you-need-to-know-about) (Razor) project as seen below:

![FileUpload in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/2f001c1c-daea-4fa7-856d-7c72a1883508/images/0c894544-4622-43e7-b035-f7b0425e8cd9.png)

Choose Razor as the view engine and click OK.

![FileUpload in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/2f001c1c-daea-4fa7-856d-7c72a1883508/images/44df86c6-fa84-446d-a87b-80aec2d9a7d1.png)

Add a [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) in [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project) and give name as HomeController as shown in the below figure:

![FileUpload in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/2f001c1c-daea-4fa7-856d-7c72a1883508/images/ced6bf26-466f-49ed-b2bf-f07f1bf1fd70.png)

Add a view (Index) and create a file upload control with the help of HTML as shown below:

```
<html>
<head>
     <title>Index</title>
</head>
<body>
     <div>
         <h2>Upload File</h2>
         <form  method="post" enctype="multipart/form-data">
            <label>Filename: <input type="file" name="file" /></label>
            <input type="submit" value="Submit" />
         </form>
     </div>
</body>
</html>
```

After adding a control in view adds the following code in the controller to upload the file on the server:

```
using System.Web.Mvc;
using System.IO;
using System.Web;

namespace FileUploadDemo.Controllers
{
     public class HomeController :  Controller
    {
         public ActionResult Index()
         {
            return View();
         }

         [HttpPost]
         public ActionResult Index(HttpPostedFileBase file)
         {
            var fileName = Path.GetFileName(file.FileName);
            if (fileName !=  null)
                file.SaveAs(Server.MapPath("~\\files\\" + fileName));
            return View();
         }
    }
}
```

Run this application , you will see the following screen:

![FileUpload in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/2f001c1c-daea-4fa7-856d-7c72a1883508/images/cd7230f8-9864-48b2-86fd-6f1157c0e5be.png)

Thanks for [reading](https://www.mindstick.com/articles/126273/books-commonly-found-on-college-reading-lists) this article, I think this will help you a lot.

---

Original Source: https://www.mindstick.com/articles/772/fileupload-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
