Monday, July 13, 2009

File Upload in ASP.Net MVC application


This article will show how to upload a file from client to server location in ASP.Net MVC application in 5 easy steps.

Step 1:

Create an ASP.Net MVC application.

File->New->Project->web->ASP.Net MVC Application

Step 2:

Creating controller

a. Right click on Controller folder and add a new controller.


FileUpload is name of the controller here. Don't check the checkbox.

Description of HttpPostedFileBase class

For uploading the file in specified path at server
HttpPostedFileBase class from System.Web namespace would be used.

HttpPostedFileBase class

  1. This contains 4 properties
  2. This contains one virtual method.
  3. FileName property will be used to fetch the file name of the file.
  4. SaveAs method will be used to save the file at server location.

See full detail:

No comments: