Arquivos de etiquetas: SharePoint Web Services

Lists.asmx, GetListItems e carpetas

Eu estaba facendo unha investigación para alguén hoxe en todo o servizo web list.asmx seleccionado como parte do SharePoint 2010 (e máis cedo).  Ela foi capaz de obter os elementos da lista no cartafol raíz (incluíndo os nomes dos subcartafoles), pero non podía elementos en subcartafoles.  I did some looking around on the internets and it’s a surprisingly common question.  Aínda, I couldn’t get a good answer to the simple question, “if I know the folder, how do I get the items in the folder?"  To be honest, I didn’t try all that hard since I’ve wanted to figure this one out on my own for a while sorriso.

To set this up, I created a site named “Blogging Scenarios” and a custom list named “Custom List with Sub Folders”.  I then created folders named:

  • Year 2005
  • Year 2006
  • Year 2007

I added a few items to the folder “Year 2006”.  Isto é o que parece:

image

My friend isn’t writing C# code but rather using Java, so the SOAP envelope was what she really needed.  To get that, I wrote a bit of jQuery and then used fiddler to get the actual HTTP conversation.

Here’s the relevant jQuery (I copied the code down below if you want to copy/paste):

image

They first key is to include both a <queryOptions> e <QueryOptions> node.  The second key is that the <Folder> node is a URL to which the client has access.

There may be other ways to get this, but this worked well for me when using jQuery.

Here is the SOAP envelope for the above:

<soapenv:Envelope xmlns:soapenv=’http://schemas.xmlsoap.org / xabón / Sobre /’>                
  <soapenv:Corpo>
    <GetListItems xmlns=’
http://schemas.microsoft.com / SharePoint / xabón /’>
      <listName>Custom List with Sub Folders</listName>
      <viewFields>  
        <ViewFields>
          <FieldRef Name=’Title’ />
          <FieldRef Name=’EncodedAbsUrl’ />
        </ViewFields>
      </viewFields>
      <queryOptions>
        <QueryOptions>
          <Folder>
http://demoserver1/Blogging Scenarios/lists/Custom List with Sub Folders/Year 2006</Folder>
        </QueryOptions>
      </queryOptions>
   
</GetListItems>
  </soapenv:Corpo>
</soapenv:Sobre>

A lot of examples and discussion around this led me to believe that all I need was <QueryOptions> and specify a folder name.  Para min, I need to both wrap it inside <queryOptions> as well as specify a fully qualified URL for the <Folder> node.

Here’s the jQuery AJAX setup:

$(documento).preparado(función() {
       var soapEnv =
           "<soapenv:Envelope xmlns:soapenv=’http://schemas.xmlsoap.org / xabón / Sobre /’> \
               <soapenv:Corpo> \
                    <GetListItems xmlns=’http://schemas.microsoft.com / SharePoint / xabón /’> \
                       <listName>Custom List with Sub Folders</listName> \
                       <viewFields> \
                           <ViewFields> \
                              <FieldRef Name=’Title’ /> \
                              <FieldRef Name=’EncodedAbsUrl’ /> \
                          </ViewFields> \
                       </viewFields> \
                       <queryOptions> \
                         <QueryOptions> \
                           <Folder>http://demoserver1/Blogging Scenarios/lists/Custom List with Sub Folders/Year 2006</Folder> \
                         </QueryOptions> \
                       </queryOptions> \
                   </GetListItems> \
               </soapenv:Corpo> \
           </soapenv:Sobre>";

</final>

Rexístrate para o meu blog.

Siga-me no Twitter http://www.twitter.com/pagalvin