C# – SharePoint GetListItems – Get all columns, filter by set List ID . C#

clistsharepointweb services

In this WS conumer C# code – , what's the simplest way to Get back all list columns (I only see 10 attributes avaliable) and to filter a a set ID=3. Do I have to qualify all of them in the ndViewFields? where do I place my caml Where? Thanks.

XmlDocument xmlDoc = new System.Xml.XmlDocument();
        XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
        XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
        XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");

        ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>FALSE</DateInUtc><ExpandUserField>FALSE</ExpandUserField>";
        //ndViewFields.InnerXml = "<FieldRef Name='Title' /><FieldRef Name='Title' />";  //you don't need to specifically request the 'ID' column since it will be returned regardless   
        ndViewFields.InnerXml = "<FieldRef Name='Title' />";  //you don't need to specifically request the 'ID' column since it will be returned regardless   
        ndQuery.InnerXml = "<OrderBy><FieldRef Name='Title'/></OrderBy>";

        try
        {
            XmlNode ndListItems = wList.GetListItems("MyList", string.Empty, ndQuery, ndViewFields,null, ndQueryOptions, null);

            foreach (XmlNode node in ndListItems)
            {
                if (node.Name == "rs:data")
                {

                    for (int f = 0; f < node.ChildNodes.Count; f++)

                    {
                        if (node.ChildNodes[f].Name == "z:row")
                        {
                            //Add the employee ID to my 'employeeIDs' ArrayList   
                            Titles.Add(node.ChildNodes[f].Attributes["ows_Title"].Value);

Best Answer

Your ndQuery should contain:

<Query>
  <Where>
    <Eq>
      <FieldRef Name="ID" />
      <Value Type="Counter">3</Value>
    </Eq>
  </Where>
</Query>

and ndViewFields should contain:

<ViewFields>
  <FieldRef Name="ID" />
  <FieldRef Name="Title" />
  ... all other fields you need
</ViewFields>