locked
ListItem.Folder property does not exist? RRS feed

  • Question

  • Hi,

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem_members.aspx

    and

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.folder.aspx

    But whatevery I try, the compiler tells me that the Folder property does not exist!

    Error    1    'Microsoft.SharePoint.Client.ListItem' does not contain a definition for 'Folder' and no extension method 'Folder' accepting a first argument of type 'Microsoft.SharePoint.Client.ListItem' could be found (are you missing a using directive or an assembly reference?)    C:\Users\Bas\Documents\Visual Studio 2008\Projects\Hsp2\Hsp2\Meeting.cs    253    44    Hsp2

    What is going on here!?

    Regards,

    Bas

    Thursday, May 5, 2011 1:53 PM

Answers

  •  public static void GetListItemDetails_ClientOM()
     {
    
          ClientContext clientContext = new ClientContext("http://basesmc2008");
          List list = clientContext.Web.Lists.GetByTitle("tester");
          
          
          CamlQuery camlQuery = new CamlQuery();
          camlQuery.ViewXml = @"<View>
                      <Query>
                        <Where>
                          <Eq>
                            <FieldRef Name='ID'/>
                            <Value Type='Counter'>3</Value>
                          </Eq>
                        </Where>
                      </Query>
                    </View>";
    
          camlQuery.DatesInUtc = false;
          
          ListItemCollection listItems = list.GetItems(camlQuery);
         
                           
          clientContext.Load(listItems);
    
          clientContext.ExecuteQuery();
          ListItem item1 = listItems[0];
    
          if (item1.FileSystemObjectType == FileSystemObjectType.Folder)
          {
            Folder folder = clientContext.Web.GetFolderByServerRelativeUrl(item1.FieldValues["FileRef"].ToString());
            clientContext.Load(folder);
            clientContext.ExecuteQuery();
    
    
    
          }
          
               
          
     }
    

    Here is some sample code. You need to check if the ListItem is a folder and then call Web.GetFolderByServerRelativeUrl

     


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    Thursday, May 5, 2011 3:24 PM

All replies

  • Microsoft.SharePoint.Client is the client object model used to run your code on a non-sharepoint server. The ListItem class in this library does not contain a Folder property. The msdn documentation points to the server object model where the SPListItem class does have a Folder property.

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.listitem_members.aspx


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    Thursday, May 5, 2011 1:59 PM
  • I have to revise my question a bit. I now found out that the client listitem is a different class, but still I can't find out how to get the children list items and/or files of this folder listitem.

    http://msdn.microsoft.com/en-us/library/ee546698.aspx

    There is a property for 'file' but not for 'folder'.

    How can you get the children (either files or listitems) of a listitem that is a folder?

    Thursday, May 5, 2011 2:00 PM
  •  public static void GetListItemDetails_ClientOM()
     {
    
          ClientContext clientContext = new ClientContext("http://basesmc2008");
          List list = clientContext.Web.Lists.GetByTitle("tester");
          
          
          CamlQuery camlQuery = new CamlQuery();
          camlQuery.ViewXml = @"<View>
                      <Query>
                        <Where>
                          <Eq>
                            <FieldRef Name='ID'/>
                            <Value Type='Counter'>3</Value>
                          </Eq>
                        </Where>
                      </Query>
                    </View>";
    
          camlQuery.DatesInUtc = false;
          
          ListItemCollection listItems = list.GetItems(camlQuery);
         
                           
          clientContext.Load(listItems);
    
          clientContext.ExecuteQuery();
          ListItem item1 = listItems[0];
    
          if (item1.FileSystemObjectType == FileSystemObjectType.Folder)
          {
            Folder folder = clientContext.Web.GetFolderByServerRelativeUrl(item1.FieldValues["FileRef"].ToString());
            clientContext.Load(folder);
            clientContext.ExecuteQuery();
    
    
    
          }
          
               
          
     }
    

    Here is some sample code. You need to check if the ListItem is a folder and then call Web.GetFolderByServerRelativeUrl

     


    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    Thursday, May 5, 2011 3:24 PM
  • Thanks so much! That's exactly what I needed.
    Thursday, May 5, 2011 7:11 PM