Dans mon appli, j'affiche le contenu d'un répertoire dans un treeview grâce à l'appel d'une fonction récursive.
Pour améliorer un peu l'affichage, j'aimerai rajouter l'icone correspondant à l'extension devant le nom du fichier.
voici le code que j'utilise pour afficher mon répertoire:
*code aspx:
public void PopulateTree(string dir, TreeNode node)
{
// get the information of the directory
DirectoryInfo directory = new DirectoryInfo(dir);
// loop through each subdirectory
foreach (DirectoryInfo d in directory.GetDirectories())
{
// create a new node
TreeNode t = new TreeNode(d.Name);
// populate the new node recursively
PopulateTree(d.FullName, t);
node.ChildNodes.Add(t); // add the node to the "master" node
}
// lastly, loop through each file in the directory, and add these as nodes
foreach (FileInfo f in directory.GetFiles())
{
// create a new node
TreeNode t = new TreeNode(f.Name);
// add it to the "master"
node.ChildNodes.Add(t);
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
//@"~\" désigne le répertoire de mon application en cours
PopulateTree(HttpContext.Current.Server.MapPath(@"~\"), TreeView1.Nodes[0]);
}
Je me demandais si quelqu'un pouvait m'aider sur ce coup là?
Merci