简体   繁体   中英

Create folder dynamicly on server? What is the right way?

I bougth a server on myasp.com, I wanted to create a folder dynamicly to every user in folder that called "UserData". when registering, for now, I create the directory by FTP client and the folder get the username. this method not allways works so I found the traditional method:

Directory.CreateDirectory(Server.MapPath("~") + "hey");

by using this method I get an error :Access to the path 'h:\\root\\home\\sagigamil-001\\www\\site1\\hey' is denied. However, I can check if folder exist.

What should I do? there is a way to give the server access to write to himself? what is the right way?

You probably need to ask your host to give the ASP .NET process write permissions. They might be reluctant to do so because of security reasons. If you can't get such permission, there will be no way for ASP .NET to create the folder.

You can create a directory over FTP by using this snippet:

var request = WebRequest.Create(new Uri("ftp://host/directory"));
request.Method = WebRequestMethods.Ftp.MakeDirectory;

using (var response = (FtpWebResponse)request.GetResponse()) {
    Console.WriteLine("Response status code: {0}", response.StatusCode);
}

Don't forget to set your credentials if needed (assign them to request.Credentials ). If you're still running into trouble, don't forget to post the error you're getting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM