Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all folders from TFS using TFS SDK

I am creating a TFS tool that will get "changeset information" from the TFS server.

Now, I want to provide a "TFS Browser" so that the user can browse what "branch/folder" he wants to fetch information from.

I am using a TreeView control and the GetItems function to get the items' path from TFS:

private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
    e.Node.Nodes.RemoveAt(0);
    RecursionType recursion = RecursionType.OneLevel;
    Item[] items = null;

    // Get the latest version of the information for the items.
    ItemSet itemSet = sourceControl.GetItems(e.Node.Tag.ToString(), recursion);
    items = itemSet.Items;

    foreach (Item item in items)
    {
        if (item.ServerItem == e.Node.Tag.ToString()) //Skip self
            continue;

        string filename = Path.GetFileName(item.ServerItem);

        if (Path.GetExtension(filename) == "")
        {
            TreeNode node = new TreeNode(filename, new TreeNode[] { new TreeNode() });
            node.Tag = item.ServerItem;
            e.Node.Nodes.Add(node);
        }
    }
}

The code below demonstrates that after clicking the "expand" button from a node, the app will "query" the items that are below the current "branch" (e).

However, I don't want to include files to the browser. As a quick and dirty check, I am checking if the "path" has an extension and if not, assume that it is a directory and show it. All was good until I discovered that we have a folder named "v1.1".

There is a solution. I can re-invoke GetItems and check its content. According to MSDN:

If the path argument is a file, returns a set of Items that contain just that file. If the path is a folder, returns a set of Items that contain all items in that folder. If the path contains a wildcard character, returns a set of Items in the specified folder that match the wildcard.

However, each call to GetItems take roughly a second and if a folder contains multiple files, the "expansion" of the node takes forever.

So, is there a way to just get all the "folders" from TFS? Or any other idea how to check if a path is a folder or a file?

Thanks!

like image 562
Ian Avatar asked Nov 06 '22 16:11

Ian


1 Answers

It seems that there is a member called .ItemType for Item. You can check against that.

like image 51
Ian Avatar answered Nov 13 '22 21:11

Ian