After logging on to TFS, you can start to read the source code directory tree.
In general, I do not recommend that you read the entire tree, because there are not only project files, but also project source code. If you read all the data, it will be a very big tree. Therefore, we recommend that you read only the root directory. Each time you click to open a level-1 subdirectory. In this way, you can find the file you want to select.
In the previous section, we have logged on.
// Obtain the selected project name. Here is a single project, and the PI [0] Name Pi = TPP is obtained at one time. selectedprojects; projecturl = PI [0]. name; versioncontrolserver version = server. getservice (typeof (versioncontrolserver) as versioncontrolserver; // obtain the project's first-level file directory itemset items = version. getitems (@ "$ \" + projecturl, recursiontype. onelevel );
Next, we will build the first-level directory tree of the project. The retrieved item is a directory containing the parent node, so you need to remove it before adding
// Clear the treeview1.nodes tree first. clear (); // obtain the parent node item subitem = items. items [0]; string mainsub = subitem. serveritem; foreach (item in items. items) {// remove the parent node if (mainsub = item. serveritem) {} else {treenode tnadd = new treenode (item. serveritem); tnadd. name = item. serveritem; treeview1.nodes. add (item. serveritem, item. serveritem );}}
The following figure shows the effect after execution. There are two levels of directories under the project.
Next we will create a click event for the tree. Recursively add subnodes to the clicked node.
/// <Summary> /// handle the event after the node is selected /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> private void treeview1_aftercheck (Object sender, treevieweventargs e) {If (E. action! = Treeviewaction. unknown) {version = server. getservice (typeof (versioncontrolserver) as versioncontrolserver; itemset items = version. getitems (E. node. text, recursiontype. onelevel); foreach (item in items. items) {If (E. node. TEXT = item. serveritem) {} else {// here, the name is used to store the Changeset version ID and the text storage display path E. node. nodes. add (item. serveritem, item. serveritem, item. changesetid);} e. node. expand ();}}}
The final effect is as follows.
TFS secondary development-baseline File Manager (3)-source code file reading