I have this code:
[HttpPost]
public ActionResult Edit(Photograph photo, HttpPostedFileBase image)
{
if (ModelState.IsValid)
{
if (image != null)
{
byte[] imageData = new byte[image.ContentLength];
image.InputStream.Read(imageData, 0, image.ContentLength);
System.IO.File.WriteAllBytes(HttpContext.Server.MapPath("~/Content/Images"), imageData);
}
repository.SavePhotograph(photo);
TempData["message"] = string.Format("{0} has been saved", photo.Name);
return RedirectToAction("Index");
}
else
{
return View(photo);
}
}
It is meant to take the photo uploaded from a form and save it in the server (local server). I’ve given the folder “Visual Studio 2010” where all the projects are kept NETWORK SERVICE user permissions and IIS_IUSRS group permissions. I’m also running visual studio as administrator.
For some reason it still won’t let me save the file to that location. The location is within the project folder under {Project_Name\Content\Images}. How do I get it to save the file there?
Thanks,
The reason it was giving me that error is because the method:
Takes, the path of the FILE and the data.
I was passing a folder
I should have been passing a file:
Now I’m getting an error with my repository so I’m looking into that 🙂 I love coding so much …. 😉