11using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
24using System . Threading . Tasks ;
35using KeeperSecurity . Vault ;
46
5-
67namespace Sample . FoldersExample
78{
89 public static class ListFolderExample
@@ -12,19 +13,54 @@ public static async Task ListFolder(VaultOnline vault = null)
1213 vault = await AuthenticateAndGetVault . ResolveVaultAsync ( vault ) ;
1314 if ( vault == null ) return ;
1415 ListFolderSimple ( vault ) ;
15-
1616 }
1717
1818 public static void ListFolderSimple ( VaultOnline vault )
1919 {
20- Console . WriteLine ( "{0,-30} {1,-46}" , "Folder Name" , "Folder UID" ) ;
21- Console . WriteLine ( new string ( '-' , 30 ) + " " + new string ( '-' , 46 ) ) ;
20+ var folders = new List < ( string Uid , string Name , string Category , int Subfolders , int Records ) > ( ) ;
21+
22+ foreach ( var nsfFolder in vault . KeeperNSFFolderNodes )
23+ {
24+ folders . Add ( (
25+ nsfFolder . FolderUid ,
26+ nsfFolder . Name ,
27+ "Nested Shared Folder" ,
28+ nsfFolder . Subfolders . Count ,
29+ nsfFolder . Records . Count ) ) ;
30+ }
2231
2332 foreach ( var folder in vault . Folders )
2433 {
25- Console . WriteLine ( "{0,-30} {1,-46}" , folder . Name , folder . FolderUid ) ;
34+ if ( string . IsNullOrEmpty ( folder . FolderUid ) )
35+ continue ;
36+
37+ folders . Add ( (
38+ folder . FolderUid ,
39+ folder . Name ,
40+ "Classic" ,
41+ folder . Subfolders . Count ,
42+ folder . Records . Count ) ) ;
2643 }
27- }
2844
45+ folders = folders . OrderBy ( f => f . Name ) . ToList ( ) ;
46+
47+ if ( folders . Count == 0 )
48+ {
49+ Console . WriteLine ( "No folders found." ) ;
50+ return ;
51+ }
52+
53+ Console . WriteLine ( "Found {0} folder(s)" , folders . Count ) ;
54+ Console . WriteLine ( "{0,-30} {1,-46} {2,-22} {3,-10} {4,-8}" ,
55+ "Folder Name" , "Folder UID" , "Category" , "Subfolders" , "Records" ) ;
56+ Console . WriteLine ( new string ( '-' , 30 ) + " " + new string ( '-' , 46 ) + " " +
57+ new string ( '-' , 22 ) + " " + new string ( '-' , 10 ) + " " + new string ( '-' , 8 ) ) ;
58+
59+ foreach ( var folder in folders )
60+ {
61+ Console . WriteLine ( "{0,-30} {1,-46} {2,-22} {3,-10} {4,-8}" ,
62+ folder . Name , folder . Uid , folder . Category , folder . Subfolders , folder . Records ) ;
63+ }
64+ }
2965 }
3066}
0 commit comments