SharePoint GetListItems - 获取所有列,按设置列表ID进行筛选。 C#

时间:2011-04-07 15:55:51

标签: c# web-services sharepoint list

在这个WS conumer C#代码中,获取所有列表列的最简单方法是什么(我只看到10个属性可用)并过滤一组ID = 3。我是否必须在ndViewFields中限定所有这些内容?我在哪里放置我的Caml在哪里?感谢。

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);

2 个答案:

答案 0 :(得分:4)

你的ndQuery应该包含:

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

和ndViewFields应包含:

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

答案 1 :(得分:2)

整个XML应如下所示:

  <?xml version="1.0" encoding="utf-8" ?> 
 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
 <GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
  <listName>GUID Or Name</listName> 
 <query>
  <Query xmlns="">
   <Where>
    <Eq>
      <FieldRef Name="ID" /> 
      <Value Type="Counter">1</Value> 
     </Eq>
    </Where>
   </Query>
  </query>
<viewFields>
 <ViewFields xmlns="">
   <FieldRef Name="ID" /> 
   <FieldRef Name="Title" /> 
 </ViewFields>
</viewFields>
 <queryOptions>
  <QueryOptions xmlns="" /> 
  </queryOptions>
  </GetListItems>
  </soap:Body>
  </soap:Envelope>