4
Answers

Error while uploading file after deployment

Shibly  Sadik

Shibly Sadik

9y
451
1
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)