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.

4
  • "get some error" -- what error? Commented Jan 8, 2013 at 19:11
  • Access to the path 'D:\INETPUB\VHOSTS\bcharyacorporation.com\httpdocs\productImage\101\1.jpg' is denied. this is the error.. @hometoast Commented Jan 8, 2013 at 19:20
  • There you go. Whatever user the IIS service is running as doesn't have write access to create those files. Commented Jan 8, 2013 at 19:39
  • can you tell me the solution @hometoast Commented Jan 8, 2013 at 19:57

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

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.
can you please tell me where can i change the file permission to write
You can navigate to it in Windows Explorer, Right click folder -> Properties -> Security.
how can i do it in server @MikeSmithDev
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.