Shibly  Sadik

Shibly Sadik

  • NA
  • 167
  • 139.8k

Error while uploading file after deployment

Aug 13 2015 1:27 AM
I have uploaded my MVC application on appharbor for testing purpose yesterday.But after deployed,when i try to upload images from my computer it is showing me the following error:
System.UnauthorizedAccessException: Access to the path 'D:\Users\apphb2f0ef12b414003\app\_PublishedWebsites\N_Commerce\Images\s-l50010.jpg' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at System.Web.HttpPostedFileWrapper.SaveAs(String filename) at N_Commerce.Controllers.HomeController.Upload_Sample_Product(SampleProduct product, HttpPostedFileBase file) in d:\temp\btjpm4su.3lh\input\N_Commerce\Controllers\HomeController.cs:line 43
Here is my controller:
 
[HttpPost]
public ActionResult Upload_Sample_Product(SampleProduct product, HttpPostedFileBase file)
{
try
{
if (ModelState.IsValid)`
{
if (file != null)
{
var extension = Path.GetExtension(file.FileName);
file.SaveAs(HttpContext.Server.MapPath("~/Images/") + file.FileName);
product.Image = file.FileName;
}
db.SampleProducts.Add(product);
db.SaveChanges();
return RedirectToAction("ProductView");
}
}
catch (Exception ex)
{
return Content("" + ex);
}
return View();
}
I have given permission(NETWORK SERVICE) to the folder where the images are stored.But still it is not working.

Answers (4)