Programatically create directory for new user on w

2019-08-02 16:55发布

问题:

I just uploaded my site to Go Daddy and have code that creates a directory dynamically based on a user id when the user creates an account on my site. It's not creating the directory so I suppose I need to set permissions in some way but I don't have control over IIS since my site's being hosted. How do I programatically set permissions?

if(Directory.Exists(path))
                return true;

try
{
    Directory.CreateDirectory(path);
}

回答1:

You can create a file/sub directory only within the root web directory provided to your website. And GoDaddy might have provided you a login to a control panel using which you can set permissions in your directory. The following is the process to set up permissions on a godaddy account:

  1. Login using your user name/account number and password
  2. Click on My Account
  3. Click on Hosting Account List
  4. Click on Open (the web hosting package you want to open)
  5. Scroll down to content and click File Manager
  6. Select the domain folder you want to set permissions for and click permissions button on the upper control bar
  7. Set the required permissions and click OK.


回答2:

Where you have the path variable, have you tried:

if(Directory.Exists(Server.MapPath(path)))
    return true;

try
{
    Directory.CreateDirectory(Server.MapPath(path));
}

What is the format of path?



回答3:

You need to map the physical directory path using Server.MapPath Method.

string directoryPath = Server.MapPath(path);       

if(Directory.Exists(directoryPath)) 
            return true; 

try 
{ 
    Directory.CreateDirectory(directoryPath ); 
} 

On the web server you can't create a directory or file outside your website virtual directory folder.