Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i Create the Folder in my server programmtically using ASp.net

i have used the following Code:

C#
public string GetComputerName(string clientIP)
        {
            try
            {
                var hostEntry = Dns.GetHostEntry(clientIP);
                return hostEntry.HostName;
            }
            catch (Exception ex)
            {
                return string.Empty;
            }
        }

in the Above method ill give the IP Address of my Server in order to get the Machine name...

C#
protected void Button1_Click(object sender, EventArgs e)
{

    lblIP.Text = GetComputerName(txtIP.Text);
    try
    {
        string myFolder = "MyFolderName";

        string UNCpath = "\\" + lblIP.Text.Trim() +\\My_Shared\\;

        string fullPath = UNCpath + myFolder;
        Directory.CreateDirectory(fullPath);//'Create folder

    }

Using Above i can create the Folder on my local machine only...
Posted
Updated 23-Dec-11 19:33pm
v2

Make sure that you are importing/using (depending on language) the System.IO namespace for this to work. Then try like the following:

C#
string pathToCreate = "~/UserFolders/" + "NAME HERE";
if(Directory.Exists(Server.MapPath(pathToCreate))
{
   //In here, start looping and modify the path to create to add a number
   //until you get the value needed
}

//Now you know it is ok, create it
Directory.CreateDirectory(Server.MapPath(pathToCreate));


Read following article for further detail:
How To Make Directory In ASP.NET?
Creating a directory using ASP.NET 2.0 and VB .NET
 
Share this answer
 
Comments
Wendelius 24-Dec-11 3:11am    
Good answer, 5
Monjurul Habib 24-Dec-11 3:17am    
thank you
I have Found the Solution for Creating the folder on the Remote Server which has some ShareFolder with Full Access..

I have used

Directory.CreateDirectory(@"\\\\Ur Server IP Address\\Shared Folder on Server\\Name of the Folder );

That's it will create a folder for you in the desired Server.....

as its useful for storing file to the server remotely...hehehehe.....
 
Share this answer
 
Comments
prasadburuga 26-Jun-12 7:36am    
Awesome buddy...
very nice

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900