Live Chat Icon For mobile
Live Chat Icon

How to create a folder in ASP.NET

Platform: ASP.NET| Category: Files

Use System.IO namespace

VB.NET


Dim path As String = ''
try
 	’ Determine whether the directory exists.
	If Directory.Exists(path) Then
		Response.Write('That path exists already.')
		Return
	End If
	’ Try to create the directory.
	Dim di As DirectoryInfo = Directory.CreateDirectory(path)
	Response.Write(('Directory create successfully at ' + Directory.GetCreationTime(path)))
catch ex as Exception
	Response.Write (ex.Message )
end try

C#


string path = @'c:\MyDir';
try 
{
	// Determine whether the directory exists.
	if (Directory.Exists(path)) 
	{
		Response.Write ('That path exists already.');
		return;
	}
	// Try to create the directory.
	DirectoryInfo di = Directory.CreateDirectory(path);
	Response.Write('Directory create successfully at ' + Directory.GetCreationTime(path));
} 
catch(Exception ex)
{
	Response.Write (ex.Message );
}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.