ICreate form
@ Using (html. beginform ( " Index " , " Home " , Formmethod. Post, New {Enctype = " Multipart/form-Data " }))
{
<Input type = " File " Name =" File " />
<Input type = " Submit " Value = " OK " />
}
Ii. CreationControlle
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 " );
}
}