I want to make an application which can view files directly from the client desktop in the same hierarchy as of his/her google drive storage. But for that I have to get the folder hierarchy for that particular user account. In my application I am trying to view the folder hierarchy in a treeview. Below is the code:
internal async Task<TreeView> SetTreeView(TreeNode node, string fileId, TreeView treeview1)
{
TreeNode t;
if (node == null)
{
t = new TreeNode();
}
else
t = node;
FilesResource.GetRequest req = driveservice.Files.Get(fileId);
var root = req.Execute();
FilesResource.GetRequest get;
await DriveV2.Authorize();
var childrenIds = DriveV2.GetChildren(root.Id);
for ( int i = 0; i < childrenIds.Count; i++)
{
get = driveservice.Files.Get(childrenIds[i]);
var file = get.Execute();
var n = t.Nodes.Add(file.Name);
SetTreeView(n,childrenIds[i], treeview1);
}
treeview1.Nodes.Add(t);
//doc.Save("file.xml");
return treeview1;
}
Please correct me if I am wrong at any point and suggest some other implementations by which I can get the hierarchy either in a XML file(storing the IDs of folders) or directly into a treeview.
Edit: The code I've written does adds the folders into the treeview but all at the same level and not in a hierarchical format.