apekshabs
apekshabs

Reputation:

Access denied to path , when uploading image to folder in server

Am getting error when you are going to upload the file on specified folder in the server. Here I am going to upload P6100083.jpg in storeimg folder. When I am going to upload I am getting the following error:

Access to the path 'C:\inetpub\vhosts\bookmygroups.com\httpdocs\storeimg\P6100083.jpg' is denied.

Can anyone help me... How to use permisiion and were to use...

My code is while uploading image

if (FileUpload1.HasFile)
{           
    float fileSize = FileUpload1.PostedFile.ContentLength;
    float floatConverttoKB = fileSize / 1024;
    float floatConverttoMB = floatConverttoKB / 1024;
    string DirName = "storeimg";
    string savepath = Server.MapPath(DirName + "/");
    DirectoryInfo dir = new DirectoryInfo(savepath);
    // string savepath = "C:\\Documents and Settings\\ssis3\\My Documents\\Visual Studio 2005\\WebSites\\finalbookgroups\\" + DirName + "\\";

    if (fileSize < 4194304)
    {
        string filename = Server.HtmlEncode(FileUpload1.FileName);
        string extension = System.IO.Path.GetExtension(filename).ToUpper();

        if (extension.Equals(".jpg") || extension.Equals(".JPG") || extension.Equals(".JPEG") || extension.Equals(".GIF"))
        {            
            savepath += filename;                       
            FileUpload1.SaveAs(savepath);
        }
    }
}

Thanks in advance

Upvotes: 1

Views: 10820

Answers (6)

Alex Sans&#233;au
Alex Sans&#233;au

Reputation: 8750

First, make sure your code runs fine locally (I assume that something you've already done).

Then deploy to your TEST or UAT environment. If you're having issue there, then this is a configuration issue. Make sure the service account under which your website's app pool is running has access to the folder.

Please make use of C# method Path.Combine() to build up your path and avoid issues with leading or trailing / and \.

Upvotes: 0

Sumen Bhattacharya
Sumen Bhattacharya

Reputation: 1

First you check the permission is enable or not if not then go to that folder which folder has to be use for containing files then right click on folder then there will be display folder properties then click on security there will be display multiple number of user which user have to be permit then click allow that all permission will be activated.

Upvotes: 0

sevenkul
sevenkul

Reputation: 966

If you are using Plesk Panel, go to file manager of Plesk Panel. List files and folders inside "httpdocs". Each file and folder has a lock icon at the very right. Click that of "storeimg" folder to change permissions. Click advenced button. Give full permission to these:

  • Plesk IIS WP User (IWPD_214(your_login_name))
  • Plesk IIS WP User (IWPD_214(your_login_name))

And click OK.

Upvotes: 0

Roman
Roman

Reputation: 21

I have no success making my upload or any write operation on filesystem work on IIS7.

Still getting the error: Access to the path is denied.

My AppPool is running under Network Service. I have granted all kinds of accounts Full Control (Network Service, Network, IIS_IUSR, Administrator, Users, Everyone), restarted the webservice several times, studied all IIS7 settings, googled for two hours and nothing works.

IIS7 and WS2008 s-u-c-k-s. Sorry for the term. Anybody can help?

I just wanted to add: I noticed that in the upload's destination folder's Properties there's this checkbox named "Read-only (Only applies to files in folder)" and it's checked. It cannot be unchecked, comes back checked after unchecking and clicking the OK button. Is that IIS7 guarding it?

Editing this message to add the SOLUTION: My admin has turned off the silly UAC "the security confirmation feature" on our server, restarted the machine and it works now. No "write" access rights for "Network Service" or any other IIS-used account was needed. When accessing the file system in a ASP.NET web application using the integrated authentication and having the impersonation set to true in its web.confing, the file system seems to be accessed by the authentified end-user's account, not by the Network Service account which the AppPool is running under. (Many people tell you to set Network Service permissions, but that is not true.) So you need to set the "write" permissions for your end-users (usually domain users: "DOMAIN\domain users") on your particular folder.

Oh yea, and the "Read-only (Only applies to files in folder)" checkbox mentioned above does not seem to have any effect. However Microsoft says "some programs might have problems writing to such folder and you should use command line statement "attrib -r -s" to get rid of the Read-Only attribute" -- but it won't work. It will stay there checked-grayed. But don't worry about that. Microsoft becomes more and more silly every day.

Upvotes: 2

alexl
alexl

Reputation: 6851

Indead, it's a server issue.

You need to verify if the user underlying your application pool has write access to the directory.

If you use IIS7, you have a new feature that helps you give custom write to this user and dun need to change the user.

Look at this link: http://www.adopenstatic.com/cs/blogs/ken/archive/2008/01/29/15759.aspx

Hope this helps.

Upvotes: 1

Brian Rasmussen
Brian Rasmussen

Reputation: 116401

This is a server issue. Make sure you have the necessary rights to write files.

Btw, since you call ToUpper() on extension there's no reason to test for ".jpg".

Upvotes: 0

Related Questions