c# - How programmatically check is project mapped in TFS? -


i need find out project mapped locally or not code. can tfs project using microsoft.teamfoundation.client.tfsteamprojectcollectionfactory.getteamprojectcollection(), can foreach workitemstore = new workitemstore(projects) , lot of project information ismapped or mappingpath.

information i'm needed accessed source control explorer of team explorer in visual studio, need c# code.

that tried:

var projects = tfsteamprojectcollectionfactory.getteamprojectcollection(new uri(_tfsserveruri)); projects.authenticate(); var workitemstore = new workitemstore(projects); foreach (project pr in workitemstore.projects)     {         pr.islocal;     } 

upd: answer

miker's answer good, want add has 1 defect. if have root directory mapped, don't have projects root directory on local computer, miker's solution still return all projects. if don't want code act way, here solution:

tfsteamprojectcollection teamprojectcollection = tfsteamprojectcollectionfactory.getteamprojectcollection(new uri(_tfsserveruri)); teamprojectcollection.authenticate(); versioncontrolserver versioncontrol = teamprojectcollection.getservice<versioncontrolserver>();  string computername = environment.machinename; windowsidentity windowsidentity = windowsidentity.getcurrent(); // yours local workspaces workspace[] workspaces = versioncontrol.queryworkspaces(null, windowsidentity.name, computername);  foreach (project pr in workitemstore.projects)     {         var mapped = false;          foreach (workspace workspace in workspaces)         {             var path = workspace.trygetlocalitemforserveritem("$/" + pr.name);             if (!string.isnullorempty(path) && directory.exists(path))             {                 mapped = true;             }         }     // want mapped project      } 

this more generic approach, think manage customize needs (not compiled, pointing direction):

string project = "teamproject1"; string serverpath = "$/"+project; string computername = "mycomputer"; // possibly environment.computer or var tpc= tfsteamprojectcollectionfactory.getteamprojectcollection(new uri(_tfsserveruri)); tpc.authenticate(); // connect versioncontrol versioncontrolserver sourcecontrol = (versioncontrolserver)tpc.getservice(typeof(versioncontrolserver)); // iterate local workspaces foreach (workspace workspace in sourcecontrol.queryworkspaces(null, null, computername)) {   // check mapped folders   foreach (workingfolder folder in workspace.folders)   {     // e.g. $/teamproject1 contains $/  if root mapped local     if (serverpath.contains(folder.serveritem) && !folder.iscloaked)      {       console.writeline(serverpath + " mapped under "+ folder.localitem);       console.writeline("workspacename: "+workspace.name);      }   } }  

Comments