Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code but its not work

C#
[HttpPost]
public ActionResult AddUser(HttpPostedFileBase file)
{
   if (file.ContentLength > 0)
   {
      string name = Path.GetFileName(file.FileName);
   }
   return View();
}

here is html code
HTML
<input type="file" id="image"/>
Posted
Updated 19-Aug-14 22:40pm
v3

check if HttpPostedFileBase object is not null by making break point, and if it have value use code like
C#
var path = "";
var fileName = "";
string logo = "";
    fileName = Path.GetFileName(file.FileName);
    string Date = DateTime.Now.ToShortDateString();
    string Millesec = DateTime.Now.Millisecond.ToString();
    string Add = Date.Replace("/", "") + Millesec;
     logo = Add + fileName;

    path = Path.Combine(Server.MapPath("~/Images/profile/"), logo);
    file.SaveAs(path);
 
Share this answer
 
Hi,

Check the below url the problem is same as that of yours
http://stackoverflow.com/questions/16255882/how-to-upload-image-display-image-in-asp-net-mvc-4

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900