Thursday, May 20, 2010

Get TFS Team Project Names

Here is a method that returns a List of names of team projects available at Team Foundation Server

public static List<string> GetProjects(TeamFoundationServer tfsServer)
        {
            List <string> listProjects = new List<string>();      

            ICommonStructureService iss = (ICommonStructureService)tfsServer.GetService(typeof(ICommonStructureService));           
            ProjectInfo[] projectInfo = iss.ListProjects();

            foreach (ProjectInfo pi in projectInfo)
            {
                listProjects.Add (pi.Name);
            }                                                

            return listProjects;
        }

Thursday, May 13, 2010

Some Registry Methods

Here are a couple of helper methods to work with Windows Registry:
The first method makes sure you get a reference to a registry subkey. If it does not exist it creates one first. The second one is a preferred way to read a registry value.



 public static RegistryKey GetKey(string RegKey)
 {
     RegistryKey Key = Registry.CurrentUser.OpenSubKey(RegKey, true);

     if (Key == null)
     {
         Key = Registry.CurrentUser.CreateSubKey(RegKey);
     }
     return Key;
}

public static string ReadRegistryValue(RegistryKey key, string regValName)
{
     string[] values = key.GetValueNames();
     if (values.Contains(regValName))
          return key.GetValue(regValName).ToString();
     else
          return String.Empty;
}