cagin
cagin

Reputation: 5920

Access to the path while image uploading

I m trying to image upload to server. Here is my code:

try
{
   fuImage.SaveAs(Server.MapPath("..\\App_Upload\\Product\\") + fileName);
}
catch (Exception exc)
{
   dvMessage.InnerHtml = WebUtil.CreateAlert(WebUtil.NotifyMessage.Warning,"İşlem Başarısız!", "Resim Dosyası eklerken hata oluştu. HATA:" + exc.Message);
   return;
}

It works in my local computer but on server, it returns Access to the path 'D:\inetpub\karahanresim.com\test.karahanresim.com\App_Upload\Product\2012722165754.jpg' is denied.

Do you know any suggestion for me?

Upvotes: 0

Views: 903

Answers (2)

Hogan
Hogan

Reputation: 70513

Remember IIs caches permissions. If you change permissions on the server you have to reset IIs

 C:\> iisreset

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

You will have to grant sufficient permissions to the account that your site is configured to run under in IIS so that it can write to this folder.

And by the way I would rewrite your code like so:

var productPath = Server.MapPath("~/App_Upload/Product");
fuImage.SaveAs(Path.Combine(productPath, fileName));

Upvotes: 1

Related Questions