web services - SharePoint getlisttiitems -获取所有列,通过设置列表ID进行过滤

本文关键字:列表 设置 ID 过滤 getlisttiitems SharePoint services 获取 web | 更新日期: 2023-09-27 17:49:37

在此WS消费者c#代码中,获取所有列表列(我只看到10个可用属性)并过滤集ID=3的最简单方法是什么?我需要在ndViewFields中限定它们吗?我该把骆驼放在哪里?谢谢。

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

web services - SharePoint getlisttiitems -获取所有列,通过设置列表ID进行过滤

你的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>

整个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>