I have a SharePoint 2007 list that I am attempting to query using the SP GetListItems web service and then write the returned values to a repeating table in InfoPath 2007. I am very close to putting this altogether but am having trouble selecting the data I want in the query results.
Thanks in advance!
Here is my code:
public void getListData()
{
WS_Lists.Lists myservice = new WS_Lists.Lists();
myservice.Credentials = System.Net.CredentialCache.DefaultCredentials;
myservice.Url = "http://portal-pd/pwa/plans/_vti_bin/Lists.asmx";
try
{
// Assign values to pass the GetListItems method
string listName = "{3DDECEF5-9660-4017-A099-9E4C24788439}";
string viewName = "{4751608D-6E7A-4F4F-BBCE-F0328F6A66E3}";
string rowLimit = "10000";
// Instantiate an XmlDocument object
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
System.Xml.XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");
//Use CAML query
query.InnerXml = "<Where><Eq><FieldRef Name=\"Division\" />" +
"<Value Type=\"Text\">Atlanta</Value></Eq></Where>";
viewFields.InnerXml = "<FieldRef Name=\"Community\" /><FieldRef Name=\"ProjectDescription\" /><FieldRef Name=\"ProjectStatus\" />";
queryOptions.InnerXml = "";
System.Xml.XmlNode secDSNav = myservice.GetListItems(listName, viewName, query, viewFields, rowLimit, null, null);
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.LoadXml(secDSNav.OuterXml);
XPathNavigator navigator = xd.CreateNavigator();
XPathNodeIterator rows = navigator.Select("/listitems/data/row", NamespaceManager);
while (rows.MoveNext())
{
string community = rows.Current.SelectSingleNode("@Community", NamespaceManager).Value;
string projectname = rows.Current.SelectSingleNode("@ProjectDescription", NamespaceManager).Value;
string projectstatus = rows.Current.SelectSingleNode("@ProjectStatus", NamespaceManager).Value;
// Add the item to the repeating table
AddItem(community, projectname, projectstatus);
}
// Remove the first empty item from the repeating table
DeleteFirstEmptyItem();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void AddItem(string community, string projectname, string projectstatus)
{
XmlDocument doc = new XmlDocument();
XmlNode group = doc.CreateElement("group13",NamespaceManager.LookupNamespace("my"));
XmlNode field = doc.CreateElement("field21",NamespaceManager.LookupNamespace("my"));
XmlNode node = group.AppendChild(field);
node.InnerText = community;
field = doc.CreateElement("field22",NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = projectname;
field = doc.CreateElement("field23",NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = projectstatus;
doc.AppendChild(group);
MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group12",NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
}
private void DeleteFirstEmptyItem()
{
XPathNavigator domNav = MainDataSource.CreateNavigator();
XPathNavigator itemNav = domNav.SelectSingleNode("/my:myFields/my:group12/my:group13[1]",NamespaceManager);
if (itemNav != null)
itemNav.DeleteSelf();
}