Open dialog box and Get file path in MVC

2.7k views Asked by At

am beginner to mvc. I have a slightly unusual situation.i have converting my windows project to MVC web application using razor.

What i needed is Click the button and open dialog box and my to Get file path from dialog box to textbox Like C:\user\Accentra\Desktop\durai

thanks advance

Durai

1

There are 1 answers

0
Ahmed ilyas On

Not sure what you mean here. are you referring to a file upload, so the user presses a button, selects the file and then save it to the server? if so...

you can have a say, file upload control when the user can then upload a file - on POST, the value gets posted to you to which then you do what you need to when saving to the server.

example:

public ActionResult Index(HttpPostedFileBase file) {

  if (file.ContentLength > 0) {
    var fileName = Path.GetFileName(file.FileName);
    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
    file.SaveAs(path);
  }

  return RedirectToAction("Index");
}