0

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?

Omar
  • 16,329
  • 10
  • 48
  • 66
cagin
  • 5,772
  • 14
  • 74
  • 130

2 Answers2

1

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));
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I gave all write permissions to folder from FileZilla. – cagin Jul 22 '12 at 14:09
  • 1
    Either you gave permissions to the wrong account or you didn't correctly gave write permission. It's as simple as that. Don't look for problems in your code, there aren't (except the small one I noticed). It's a configuration/permission issue. If you have specific questions configuring your web server you should post on http://serverfault.com. Stack Overflow is a programming related Q&A site. – Darin Dimitrov Jul 22 '12 at 14:10
  • I talked about porblem with hosting company. They told me "You can not give permissions to folders on ftp applications." They gave permissions. – cagin Aug 03 '12 at 08:59
0

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

 C:\> iisreset
Hogan
  • 69,564
  • 10
  • 76
  • 117