create folder dynamically
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CreateTreeView();
}
public void CreateTreeView()
{
TreeView tv = new TreeView();
DirectoryInfo dir = new DirectoryInfo("E:\\way backup");//give path of Root directory
TreeNode tnRoot = new TreeNode();
tnRoot.Text = dir.Name;
tnRoot.Value = dir.FullName;
tv.Nodes.Add(tnRoot);
AddDirs(dir, tnRoot);
tv.SelectedNodeChanged += new EventHandler(tv_SelectedNodeChanged);
PlaceHolder1.Controls.Add(tv);
}
void tv_SelectedNodeChanged(object sender, EventArgs e)
{
TreeView tv = (TreeView)sender;
Response.Write(tv.SelectedNode.Value);
}
public void AddDirs(DirectoryInfo dir, TreeNode parent)
{
DirectoryInfo[] dirs = dir.GetDirectories();
foreach (DirectoryInfo d in dirs)
{
TreeNode tn = new TreeNode();
tn.Text = d.Name;
tn.Value = d.FullName;
parent.ChildNodes.Add(tn);
AddDirs(d, tn);
}
}
}
public void GetDir_files(string sourceDir)
{
Response.Write(sourceDir + "<br /><br />");
string[] fileEntries = Directory.GetFiles(sourceDir);
foreach (string fileName in fileEntries)
{
// do something with fileName
Response.Write(fileName + "<br />");
}
// Recurse into subdirectories of this directory.
string[] subdirEntries = Directory.GetDirectories(sourceDir);
foreach (string subdir in subdirEntries)
if ((File.GetAttributes(subdir) & FileAttributes.ReparsePoint) !=
FileAttributes.ReparsePoint)
GetDir_files (subdir);
}
for more detail:http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/contextmenu/defaultcs.aspx