Help On Creating SubFolder with in a Folder

Posted by Vijayar under C# on 2/17/2012 | Points: 10 | Views : 1704 | Status : [Member] | Replies : 6
Hi
I need to create a sub folder with in a folder in a specified path,by checking whether
the folder exist.If exist message should be displayed as folder already exist ,other wise create a folder,in the specified folder.I.e.I have a folder called Gallery,in gallery folder i need to create a sub folder called events and so on .Help Me

vijaya


Responses

Posted by: Sekar.c on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
what you want windows or web application ?

sekar

Regards
Sekar.c

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sekar.c on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Try this code
private void button1_Click(object sender, EventArgs e)
{
if (Directory.Exists("D:\\sample\\rr") == false)
{

Directory.CreateDirectory("D:\\sample\\rr");

}
else
{
MessageBox.Show("folder already exist");
}

}
sekar

Regards
Sekar.c

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
  public static string fname;

public static string Path;
public static string fldname;
public static bool mess;

public static bool createFolder(string sPath, string foldername)
{
#region Check folder Name
bool chkTool = Directory.Exists(sPath);
if (chkTool)
{
fname = @"\" + foldername + "\\";
fname = sPath + fname;
Directory.CreateDirectory(fname);
mess = true;
}
else if (!chkTool)
{
if (!Directory.Exists(sPath))
{
Directory.CreateDirectory(sPath);
}
fname = @"\" + foldername + "\\";
fname = sPath + fname;
Directory.CreateDirectory(fname);
mess = true;
}
#endregion Check folder Name
return mess;

}
Path = @"E:\Test";
fldname = "Test1";
bool chk = createFolder(Path, fldname);
if (chk)
{
MessageBox.Show("Folder Created");
}
else
{
MessageBox.Show("Folder is not Create");
}


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
Hi
I need in web application.In a form i have a text box,a subfolder should be created in a folder called gallery in my project.I need to create a subfolder under this folder

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
check this link
http://www.dotnetfunda.com/forums/thread2356-create-sub-folder-in-aspnet.aspx

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pradeepkumar417 on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

You can create a sub folder in a folder by writing below code.

if (Directory.Exists(Server.MapPath("gallery\\subfolderName ")))
{
Response.write("Folder already exists");
}
else
{
Directory.CreateDirectory(Server.MapPath("gallery\\subfolderName "));
}

Thanks & Regards,
Software Engineer,
Pradeep Kumar

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response