c# - Can't add a tag using system.io file, as i need it to be cast as a fileinfo object later in my code -


the tag file anode causing errors directory anode, because 1 , same? think casting tag fileinfo object isn't working. suggestions how fileinfo nodes user selects populate listview?

//see code below attempts made add tags foreach (directoryinfo subdir in subdirs)         {             anode = new treenode(subdir.name, 0, 0);             anode.tag = subdir;             anode.imagekey = "folder";             anode.imageindex = 0;             anode.selectedimageindex = 1;             subsubdirs = subdir.getdirectories();              if (subsubdirs.length != 0)             {                 getdirectories(subsubdirs, anode);             }              //add files treeview             foreach (var file in subdir.getfiles())             {                 if(file.name.contains(".rfa"))                 {                 anode.nodes.add(new treenode(file.name));             //cant add tag file directory              anode.tag = file;                                 }             }              nodetoaddto.nodes.add(anode);         } 

1) in order check file's extension, it's better practice use:

file.extension.equals(".rfa", stringcomparison.ordinalignorecase); 

2) you're modifying anode 'tag' property, causing problem, try modifying follows:

anode.nodes.add(new treenode(file.name){tag=file}); 

3) imho, should not keep fileinfo/directoryinfo object in 'tag', rather use path itself

4) if want display directory's structure in treeview, @ following: https://stackoverflow.com/a/6239644/120391 [you can modify display '.rfa' files]


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -