public static List <SPPrincipal> GetGroupsByDeptCodeField(this SPListItem item, string DeptCodeFieldName, string GroupSuffix) { List <SPPrincipal> codeFieldGroups = new List <SPPrincipal>(); string[] codeNames; if (!item.ParentList.Fields.ContainsField(DeptCodeFieldName)) { return(codeFieldGroups); } codeNames = item.GetCodesFromDeptCodeField(DeptCodeFieldName); foreach (string code in codeNames) { string groupName = code + GroupSuffix; SPPrincipal CodeGroup; try { CodeGroup = item.ParentList.ParentWeb.SiteGroups.GetByName(groupName); } catch { continue; } codeFieldGroups.Add(CodeGroup); } return(codeFieldGroups); }