0

I'm trying to create a folder using the two methods below.

Method 1

if (directoryInfo.Exists)
{
    directoryInfo.CreateSubdirectory(ddlCat.SelectedItem.Text);
    Label1.Text = "Directory " + ddlCat.SelectedItem.Text + " Created";
}

Method 2

var folder = Server.MapPath("~/UploadImages/" + ddlCat.SelectedItem.Text);

if (!Directory.Exists(folder))
{
    DirectoryInfo di = Directory.CreateDirectory(folder);
}            

Where ddlCat is a dropdownlist.

before executing the code, I modified the permission of the folder to Full for the current user. However, I'm still getting this error:

UnauthorisedAccessException was unhandled by the user code Access to the path 'Accessories' is denied.

The folder in which I'm creating subfolder is "c:\inetpub\wwwroot\xyz\UploadImages"

Can someone please guide me?

Jason Evans
  • 28,906
  • 14
  • 90
  • 154
Itniv
  • 112
  • 2
  • 2
  • 11
  • Not this one again, hold on.... – Liam Mar 25 '14 at 09:43
  • 3
    Access denied is usually access denied. Have you verified that the app pool account has the appropriate permissions to that directory? – Steve Andrews Mar 25 '14 at 09:43
  • possible duplicate of [System.UnauthorizedAccessException while creating a file](http://stackoverflow.com/questions/15974590/system-unauthorizedaccessexception-while-creating-a-file) – Liam Mar 25 '14 at 09:44
  • Have you granted permission to the IIS user? – Marc Mar 25 '14 at 09:44
  • Or [Unauthorized Access exception when i try to create a directory](http://stackoverflow.com/questions/16833482/unauthorized-access-exception-when-i-try-to-create-a-directory) – Liam Mar 25 '14 at 09:45
  • @marc Thanks marc your quick response solved my problem.. by default the "IIS_USERS" user permission are available but the IUSR permission are not there.. Now i have added IUSR and the problem solved now im able to create Folders – Itniv Mar 25 '14 at 09:50
  • @liam sorry Liam , i tried to search the forum for the question . but my search query didnt yield any relavent result so i created a new question. – Itniv Mar 25 '14 at 09:53
  • Don't apologise, @Phanindra, we get much worse trust me. This is a duplicate though. – Liam Mar 25 '14 at 10:05

0 Answers0