my site is hosted at IIS7.5
i have a controller action as below
[HttpPost]
public ActionResult Create(ClientDocument clientdocument,HttpPostedFileBase FilePath)
{
if (ModelState.IsValid)
{
try
{
if (FilePath != null && FilePath.ContentLength > 0)
{
var filename = Path.GetFileName(FilePath.FileName);
string ext = filename.Split(char.Parse(".")).LastOrDefault();
clientdocument.FilePath = clientdocument.Title + "." + ext;
var path = Path.Combine(Server.MapPath("~/Uploads"), clientdocument.Title + "." + ext);
FilePath.SaveAs(path);
db.ClientDocuments.Add(clientdocument);
db.SaveChanges();
return RedirectToAction("../");
}
}
catch(Exception ex)
{
return HttpNotFound("There Was A Problem Uploading File And Creating A Record");
}
}
ViewBag.ClientID = new SelectList(db.Clients, "ClientID", "FullName", clientdocument.ClientID);
return View(clientdocument);
}
when i click the button it tries to upload the file but then show following error message
http 404 file or directory not found
the resource you are looking for might have been removed,had its name changed or is temp unavailable
please assist how to configure iis7.5 to upload this file while in VS2010 every thing is working fine.
EDIT
After Changes @keshav Mentioned
View:
@using (Html.BeginForm("Create", "ClientDocument", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Attach New Client Document</legend>
<div class="editor-label">
@Html.LabelFor(model => model.FilePath)
</div>
<div class="editor-field">
<input type="file" id="FilePath" name="FilePath" />
@Html.ValidationMessageFor(model => model.FilePath)
</div>
<fieldset>
}
and Controller:
[HttpPost,ActionName("Create")]
public ActionResult Create(ClientDocument clientdocument,HttpPostedFileBase FilePath)
{
if (ModelState.IsValid)
{
try
{
if (FilePath != null && FilePath.ContentLength > 0)
{
var filename = Path.GetFileName(FilePath.FileName);
string ext = filename.Split(char.Parse(".")).LastOrDefault();
clientdocument.FilePath = clientdocument.Title + "." + ext;
var path = Path.Combine(Server.MapPath("~/Uploads"), clientdocument.Title + "." + ext);
FilePath.SaveAs(path);
db.ClientDocuments.Add(clientdocument);
db.SaveChanges();
return RedirectToAction("Index", "Home");
}
}
catch(Exception ex)
{
return HttpNotFound("There Was A Problem Uploading File And Creating A Record");
}
}
ViewBag.ClientID = new SelectList(db.Clients, "ClientID", "FullName", clientdocument.ClientID);
return View(clientdocument);
}
still i am having same problem as before.
As far as I know you shouldn’t have to change any settings in IIS…
further to what @Darin Dimitrov said about the exception can you change the code in the catch clause to:
and in your error page (should have one under the shared view folder) add the following line
I am thinking the code is throwing some exception on the server but not when you run it locally. This will help you narrow down problem. If you are still getting an 404 error then there probably is a setting issue.