---
title: "How to Upload File in ASP.NET MVC 3.0?"  
description: "How to Upload File in ASP.NET MVC 3.0?"  
author: "Anonymous User"  
published: 2014-11-17  
updated: 2014-11-18  
canonical: https://www.mindstick.com/forum/12613/how-to-upload-file-in-asp-dot-net-mvc-3-0  
category: "asp.net mvc"  
tags: ["c#", "mvc3", "file", "upload"]  
reading_time: 1 minute  

---

# How to Upload File in ASP.NET MVC 3.0?

I want to [upload](https://www.mindstick.com/forum/12860/how-to-upload-file-asynchronously-using-generic-handler) [file in asp.net](https://www.mindstick.com/forum/158972/how-to-read-appsettings-values-from-a-json-file-in-asp-dot-net-core) [mvc](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc). How can I upload the file using [html input](https://www.mindstick.com/forum/157343/how-to-prevent-a-user-from-adding-same-character-over-and-over-in-html-input-box-using-javascript) file [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control)?

## Replies

### Reply by Anonymous User

You don't use a [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) control. Server side controls are not used in [ASP.NET MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc).

So you would start by creating an [HTML](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript) form which would contain a file input:

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

and then you would have a controller to handle the upload:

```
public class HomeController : Controller{    // This action renders the form    public ActionResult Index()    {        return View();    }     // This action handles the form POST and the upload    [HttpPost]    public ActionResult Index(HttpPostedFileBase file)    {        // Verify that the user selected a file        if (file != null && file.ContentLength > 0)         {            // extract only the fielname            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");            }}
```


---

Original Source: https://www.mindstick.com/forum/12613/how-to-upload-file-in-asp-dot-net-mvc-3-0

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
