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 Application (Razor) project as seen below:
Choose Razor as the view engine and click OK.
Add a controller in your project and give name as HomeController as shown in the below figure:
Add a view (Index) and create a file upload control with the help of HTML as shown below:
<form method="post" enctype="multipart/form-data">
<label>Filename: <input type="file" name="file" /></label>
<input type="submit" value="Submit" />
After adding a control in view adds the following code in the controller to upload the file on the server:
public class HomeController : Controller
public ActionResult Index()
public ActionResult Index(HttpPostedFileBase file)
var fileName = Path.GetFileName(file.FileName);
if (fileName != null)
file.SaveAs(Server.MapPath("~\\files\\" + fileName));
Run this application , you will see the following screen:
Thanks for reading this article, I think this will help you a lot.