// Creates a Dictionary of DGS Servers, using the server name as the key private static ServerCollection CreateServerItemList() { ServerCollection itemDic = new ServerCollection(); // Get the Server Inventory as a ListItemCollection ListItemCollection list = GetServerListItems(); // Itterate through each item in the list foreach (ListItem lItem in list) { try { ServerItem serv = new ServerItem(lItem["Title"].ToString().ToLower()); // Get each user in the "Support Staff" field var str = (FieldUserValue[])lItem.FieldValues[_supportStaffField]; // Add support staff if it exists if (str != null) { foreach (FieldUserValue user in str) { serv.AddStaff(user.LookupValue); } } // Set the simple text fields serv.BusinessUnit = lItem[_businessUnitField] != null ? (string)lItem[_businessUnitField] : ""; serv.ServerType = lItem[_serverTypeField] != null ? (string)lItem[_serverTypeField] : ""; serv.Environment = lItem[_environmentField] != null ? (string)lItem[_environmentField] : ""; // Set the FieldNote value for Server Description string description = lItem[_serverDescriptionField] != null ? lItem.FieldValuesAsText[_serverDescriptionField] : ""; // Remove non-ASCII characters from the string description = description.Replace("\n", ""); description = Regex.Replace(description, @"[^\u0000-\u007F]", string.Empty); serv.ServerDescription = description; // Add server to the Dictionary if (!itemDic.ContainsKey(serv.ServerName)) { itemDic.Add(serv); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(itemDic); }