0

i am trying to upload image and store it in file system in asp.net using c#. i am using this code

 if (FileUpload1.HasFile)
    {
        if ((FileUpload1.PostedFile.ContentType == "image/jpeg") ||
           (FileUpload1.PostedFile.ContentType == "image/png") ||
           (FileUpload1.PostedFile.ContentType == "image/tmp") ||
           (FileUpload1.PostedFile.ContentType == "image/gif"))
        {
            if (Convert.ToInt64(FileUpload1.PostedFile.ContentLength) < 10000000)
            {
                string filename = Label1.Text;
                FileUpload1.SaveAs(Server.MapPath("productImage\\" + ddlproductId.Text + "\\" + filename + ".jpg"));

            }
        }
    }

it actually work fine in my computer but while i am uploading it on server it get some error. please help me. thanking you.

1 Answers1

2

Sounds like a permissions problem. You'll want to change the security of that folder on the web server and ensure NETWORK SERVICE has Write permissions. Or, if you have an older server, it will be ASPNET.

MikeSmithDev
  • 15,731
  • 4
  • 58
  • 89
  • That should work with default settings. If the IIS settings have been changed you should check to see what user it runs as. If you are using an AppPool it will be the user the AppPool runs as that you need to give permissions. – toby Jan 08 '13 at 19:44
  • can you please tell me where can i change the file permission to write – Manish Sasmal Jan 08 '13 at 19:55
  • You can navigate to it in Windows Explorer, Right click folder -> Properties -> Security. – MikeSmithDev Jan 08 '13 at 19:57
  • how can i do it in server @MikeSmithDev – Manish Sasmal Jan 08 '13 at 19:59
  • What do you mean "in server"? I was referring to when you are logged into the server and then go run Windows Explorer and navigate to the folder. – MikeSmithDev Jan 08 '13 at 20:02
  • Perhaps this will help if you are looking for code solution: http://stackoverflow.com/questions/130617/how-do-you-check-for-permissions-to-write-to-a-directory-or-file – MikeSmithDev Jan 08 '13 at 20:15