title: Why does <ViewFields> criteria get ignored by the SharePoint List Service's GetListItems Method
body: <p>Although I specify a ViewFields element in my sharepoint list service's GetListItems query, all fields are returned. The following code builds the request:</p>
  
  <pre><code>XmlDocument xmlDoc = new System.Xml.XmlDocument();
  XmlNode query = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
  XmlNode viewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
  XmlNode queryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");    
  
  ... set query ...
  
  viewFields.InnerXml = "&lt;FieldRef Name='LinkFilename' /&gt;&lt;FieldRef Name='FileDirRef' /&gt;&lt;FieldRef Name='FileLeafRef' /&gt;";            
  
  queryOptions.InnerXml = "&lt;IncludeMandatoryColumns&gt;FALSE&lt;/IncludeMandatoryColumns&gt;&lt;DateInUtc&gt;TRUE&lt;/DateInUtc&gt;&lt;Folder&gt;Resource Management Tools&lt;/Folder&gt;&lt;ViewAttributes Scope='Recursive' /&gt;";
  
  XmlNode xmlNode = SharePointListWebService.GetListItems(
  _listServiceConfigurationSettings.ListName,
                                  string.Empty,
                                  query,
                                  viewFields,
                                  null,
                                  queryOptions,
                                  null);
  </code></pre>
  
  <p>According to fiddler, this results in the following soap envelope being posted to the list service:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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"&gt;
    &lt;soap:Body&gt;
      &lt;GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;    
        &lt;listName&gt;Shared Documents&lt;/listName&gt;
        &lt;viewName /&gt;
        &lt;query&gt;
          &lt;Query xmlns=""&gt;
            &lt;Where&gt;
              &lt;And&gt;
                &lt;Contains&gt;
                  &lt;FieldRef Name="FileLeafRef" /&gt;
                  &lt;Value Type="Text"&gt;.xls&lt;/Value&gt;
                &lt;/Contains&gt;
                &lt;Geq&gt;
                  &lt;FieldRef Name="Modified"
                  IncludeTimeValue="True" /&gt;
                  &lt;Value Type="DateTime"&gt;2010-05-10T11:53:32Z&lt;/Value&gt;
                &lt;/Geq&gt;
              &lt;/And&gt;
            &lt;/Where&gt;
            &lt;OrderBy&gt;
              &lt;FieldRef Name="FileDirRef" /&gt;
            &lt;/OrderBy&gt;
          &lt;/Query&gt;
        &lt;/query&gt;
        &lt;viewFields&gt;
          &lt;ViewFields xmlns=""&gt;
            &lt;FieldRef Name="LinkFilename" /&gt;
            &lt;FieldRef Name="FileDirRef" /&gt;
            &lt;FieldRef Name="FileLeafRef" /&gt;
          &lt;/ViewFields&gt;
        &lt;/viewFields&gt;
        &lt;queryOptions&gt;
          &lt;QueryOptions xmlns=""&gt;
            &lt;IncludeMandatoryColumns&gt;FALSE&lt;/IncludeMandatoryColumns&gt;
            &lt;DateInUtc&gt;TRUE&lt;/DateInUtc&gt;
            &lt;Folder&gt;Resource Management Tools&lt;/Folder&gt;
            &lt;ViewAttributes Scope="Recursive" /&gt;
          &lt;/QueryOptions&gt;
        &lt;/queryOptions&gt;
      &lt;/GetListItems&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>and the following soap response being returned from the service:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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"&gt;
    &lt;soap:Body&gt;
      &lt;GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;
        &lt;GetListItemsResult&gt;
          &lt;listitems xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
          xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
          xmlns:rs='urn:schemas-microsoft-com:rowset'
          xmlns:z='#RowsetSchema'&gt;
            &lt;rs:data ItemCount="19"&gt;
              &lt;z:row ows_LinkFilename='[SENSITIVE DATA].xls'
              ows_FileDirRef='278;#sites[SENSITIVE DATA]'
              ows_FileLeafRef='278;#[SENSITIVE DATA].xls'
              ows_MetaInfo='278;#Subject:SW| vti_parserversion:SR|12.0.0.6421 ContentTypeId:SW|0x0101006C2E647253A1074FB6079F08E5F2A395 _Author:SW|[SENSITIVE DATA] _Category:SW| vti_author:SR|[SENSITIVE DATA] _Comments:SW| vti_approvallevel:SR| vti_categories:VW| vti_cachedcustomprops:VX|vti_approvallevel vti_categories Subject vti_assignedto Keywords _Author _Category _Comments vti_assignedto:SR| Keywords:SW| vti_modifiedby:SR|[SENSITIVE DATA]'
              ows__ModerationStatus='0' ows__Level='1'
              ows_Last_x0020_Modified='278;#2010-06-29T18:55:38Z'
              ows_ID='278' ows_owshiddenversion='53'
              ows_UniqueId='278;#{0E51B2B1-89A7-4895-8ECC-0FE7D420470C}'
              ows_FSObjType='278;#0'
              ows_Created_x0020_Date='278;#2009-03-09T16:06:41Z'
              ows_ProgId='278;#' ows_Modified='2010-06-29T18:55:37Z'
              ows_FileRef='278;#sites[SENSITIVE DATA].xls'
              ows_DocIcon='xls'
              ows_Editor='262;#[SENSITIVE DATA]' /&gt;            
            &lt;/rs:data&gt;
          &lt;/listitems&gt;
        &lt;/GetListItemsResult&gt;
      &lt;/GetListItemsResponse&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Notice the z:row element has more fields included than I specified in my ViewFields criteria. I also set IncludeMandatoryColumns to false in my query options. Did I do something wrong or do I not understand how ViewFields really works as I thought it would limit the fields i.e. z:row attributes returned by the SharePoint list service.</p>