title: How can I get the Google drive folder hierarchy?
body: <p>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:</p>
  
  <pre><code>internal async Task&lt;TreeView&gt; 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 &lt; 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;
      }
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>