@model SimpleUpload.Models.MemberModel
ViewBag.Title = "ContactForm";
@using (Html.BeginForm("ContactForm", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
<div class="form-horizontal">
@Html.LabelFor(model => model.ImageFile, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.TextBoxFor(m => m.ImageFile, new { type = "file" })
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
I want to upload the file posted in the form group div.
//Use Namespace called : System.IO
string FileName = Path.GetFileNameWithoutExtension(membervalues.ImageFile.FileName);
//To Get File Extension
string FileExtension = Path.GetExtension(membervalues.ImageFile.FileName);
//Add Current Date To Attached File Name
FileName = DateTime.Now.ToString("yyyyMMdd") + "-" + FileName.Trim() + FileExtension;
//Get Upload path from Web.Config file AppSettings.
string UploadPath = ConfigurationManager.AppSettings["UserImagePath"].ToString();
//Its Create complete path to store in server.
membervalues.ImagePath = UploadPath + FileName;
//To copy and save file into server.
membervalues.ImageFile.SaveAs(membervalues.ImagePath);
return View();