2011-04-07 56 views
3

在這個WS conumer C#代碼中,獲取所有列表列的最簡單方法是什麼(我只能看到10個屬性可用)並過濾一個集合ID = 3。我必須在ndViewFields中限定它們嗎?我在哪裏放置我的caml在哪裏?謝謝。SharePoint GetListItems - 獲取所有列,按集List ID過濾。 C#

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

回答

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