在TFS 中把每個文件夾被抽象成“ItemSet”或“Item”,相對于父級目錄來講就是Item ,相對于子級目錄來講就是“ItemSet”。每個文件都被抽象成“Item”。
//連接TFSstring tpcURL = "http://192.168.83.62:8080";TfsTeamPRojectCollection tpc = new TfsTeamProjectCollection(new Uri(tpcURL));VersionControlServer version = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer;//獲取指定目錄下的ItemString Path="$/" ; ItemSet its = version.GetItems("$/", RecursionType.OneLevel); //獲取Path 下的所有Item, 包括Path 自己,并且是第一個。第一個參數支持通配符,如:ItemSet its = version.GetItems("$/*.xaml", RecursionType.OneLevel);// RecursionType.OneLevel 遞歸向下讀取一層// RecursionType.Full 遞歸讀取所有// RecursionType.None 不遞歸//遍歷Itemforeach (Item item in its.Items){ //item.ArtifactUri 在服務器上的絕對路徑 如:http://192.168.82.63:88/######## //item.ItemType 枚舉,表明是文件還是文件 //item.ServerItem 在服務器上的絕對路徑 如:$/CtripSolution/CommDll // item.IsBranch 是否是分支 //item.DownloadFile() 下載到本地 //......... }
結合上面的代碼,我們可以做出下面的效果:
//顯示已經刪除掉的Item string tpcURL = "http://192.168.83.62:8080"; TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(tpcURL)); VersionControlServer version = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer; ItemSpec spec = new ItemSpec("$/CtripSolution/Customer/MAINLINE/ScrmApp/SinaWeiTravel", RecursionType.Full); var deletedItems = version.GetItems(spec, VersionSpec.Latest, DeletedState.Deleted, ItemType.Any, true);
新聞熱點
疑難解答