Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a new folder in asp.net using c#?

How can I create a new folder in asp.net using c#?

like image 765
jeevamuthu Avatar asked May 27 '11 13:05

jeevamuthu


People also ask

Which method is used to create a folder in ASP?

ASP CreateFolder() Method The ASP CreateFolder Method is used to create a new directory or folder in the Server. It is a predefined method of the FileSystem Object. It accepts the name of the folder as a parameter.


4 Answers

var folder = Server.MapPath("~/App_Data/uploads/random");
if (!Directory.Exists(folder))
{
    Directory.CreateDirectory(folder);
}
like image 122
Kasper Skov Avatar answered Oct 18 '22 08:10

Kasper Skov


path is the variable holding the directory name

Directory.CreateDirectory(path);

You can read more about it here

like image 43
Robert Greiner Avatar answered Oct 18 '22 09:10

Robert Greiner


Directory.CreateDirectory. However you will have to make sure the application pool user has rights to create the directory.

like image 43
Otávio Décio Avatar answered Oct 18 '22 08:10

Otávio Décio


if (!Directory.Exists(Path)) 
{
    Directory.CreateDirectory(Path);
}

try this, for a better one.

like image 29
Sai Kalyan Kumar Akshinthala Avatar answered Oct 18 '22 09:10

Sai Kalyan Kumar Akshinthala