一:锁定(Lock)
string tpcURL = "http://192.168.83.62:8080/"; TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(tpcURL)); VersionControlServer version = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer; version.NonFatalError += version_NonFatalError; Workspace[] wss = version.QueryWorkspaces(null, Environment.UserName, Environment.MachineName); Workspace ws = wss[0]; string serverDir = "$/MySolution/Customer/MAINLINE/ScrmApp/SinaWeiTravel/SCRM.HPHY.Models"; ItemSet its = version.GetItems(serverDir, RecursionType.OneLevel); foreach (var item in its.Items) { ws.SetLock(item.ServerItem, LockLevel.CheckOut); }
二:解锁(UnLock)
相应的解锁,苦苦查找形如 “ws.UnLock(item.ServerItem)”这样的方法。可惜没有,原来解锁要使用LockLevel.None 枚举值
ws.SetLock(item.ServerItem, LockLevel. None);
//LockLevel 锁定级别:
//LockLevel.None 解锁
//LockLevel.Checkin 签入锁定
//LockLevel.CheckOut 签出锁定
//LockLevel.Unchanged