|
public void Main(ref DestinationRuleContext K2)
{
K2.ResolveQueuesToUsers = true;
// settings for this SharePoint list
string strURL = "http://k2vpc:82/sites/SPS";
string strListName = "Users";
string strColumnName = "UserID";
GetUsersFromList(K2, strURL, strListName, strColumnName);
}
private void GetUsersFromList(DestinationRuleContext K2, string strURL, string strListName, string strColumnName)
{
// instantiate the proxy webservice class
Lists listService = new Lists();
// make sure we're hitting the correct site
listService.Url = strURL + "/_vti_bin/Lists.asmx";
// use the current credentials
listService.Credentials= System.Net.CredentialCache.DefaultCredentials;
// load up a namespace manager with the namespaces we'll need for the XPaths
System.Xml.XmlNamespaceManager oMgr = new System.Xml.XmlNamespaceManager(new System.Xml.NameTable());
oMgr.AddNamespace( "sps", "http://schemas.microsoft.com/sharepoint/soap/" );
oMgr.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
oMgr.AddNamespace("z", "#RowsetSchema");
// retrieve a list of all the current lists on this virtual server
System.Xml.XmlNode ndLists = listService.GetListCollection();
// get the node containing the specific list we're interested in
System.Xml.XmlNode ndList = ndLists.SelectSingleNode("//sps:List[@Title='" + strListName + "']", oMgr);
if(ndList != null)
{
// recover the GUID for the list
string strListGUID = ndList.Attributes["ID"].InnerText;
// recover the schema for the list column
System.Xml.XmlNode ndListDefinition = listService.GetList(strListGUID);
// retrieve the definition for this column. the display name is not always what the real
// name is under the covers, so get the "real name"
System.Xml.XmlNode ndField = ndListDefinition.SelectSingleNode("//sps:Fields/sps:Field[@DisplayName='" + strColumnName + "']", oMgr);
if(ndField != null)
{
// recover the real name for this display name
string strRealName = ndField.Attributes["Name"].InnerText;
// setup a filtered view on this column name
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
viewFields.InnerXml = "<FieldRef Name='" + strRealName + "' />";
// Declare an XmlNode object and initialize it with the XML response from the GetListItems method.
System.Xml.XmlNode nodeTmpListItems = listService.GetListItems(strListGUID, "", null, viewFields, "", null);
// return all the rows (i.e. records in this list)
System.Xml.XmlNodeList ndRecs = nodeTmpListItems.SelectNodes("rs:data/z:row", oMgr);
// iterate the rows and recover the user id
foreach (System.Xml.XmlNode rec in ndRecs)
{
// build out the real attribute name
string strAttrName = "ows_" + strRealName;
// recover the value from this attribute
string strUserID = rec.Attributes[strAttrName].InnerText;
// set the K2 destination
Console.WriteLine("**** USER: " + strUserID);
K2.Destinations.Add(DestinationType.User, strUserID);
}
}
}
return;
}
|