Hi namojainashis...,
Refer below sample code.
C#
protected void Page_Load(object sender, EventArgs e)
{
string rootFolder = Server.MapPath("~/UploadDocument/");
string[] documents = new[] { "DocumentID_123_Project ID_2345", "DocumentID_12322_Project ID_234235" };
foreach (string document in documents)
{
string folder = System.IO.Path.Combine(rootFolder, document);
if (!System.IO.Directory.Exists(folder))
{
System.IO.Directory.CreateDirectory(folder);
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim rootFolder As String = Server.MapPath("~/UploadDocument/")
Dim documents As String() = {"DocumentID_123_Project ID_2345", "DocumentID_12322_Project ID_234235"}
For Each document As String In documents
Dim folder As String = System.IO.Path.Combine(rootFolder, document)
If Not System.IO.Directory.Exists(folder) Then
System.IO.Directory.CreateDirectory(folder)
End If
Next
End Sub
For creating in ftp server refer below code.
C#
string rootAddeess = "ftp://yourserver.com/UploadDocument";
string[] subDirectories = new[] { "DocumentID_123_Project ID_2345", "DocumentID_12322_Project ID_234235" };
foreach (string subDirectory in subDirectories)
{
System.Net.WebRequest request = System.Net.WebRequest.Create(rootAddeess + "/" + subDirectory);
request.Method = System.Net.WebRequestMethods.Ftp.MakeDirectory;
request.Credentials = new System.Net.NetworkCredential("UserName", "Password");
using (var response = (System.Net.FtpWebResponse)request.GetResponse())
{
}
}
VB.Net
Dim rootAddeess As String = "ftp://yourserver.com/UploadDocument"
Dim subDirectories As String() = {"DocumentID_123_Project ID_2345", "DocumentID_12322_Project ID_234235"}
For Each subDirectory As String In subDirectories
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(rootAddeess & "/" & subDirectory)
request.Method = System.Net.WebRequestMethods.Ftp.MakeDirectory
request.Credentials = New System.Net.NetworkCredential("UserName", "Password")
Using response = CType(request.GetResponse(), System.Net.FtpWebResponse)
End Using
Next