0
votes

I'm trying to list the content of a folder in SharePoint 2010 by using its web service.

This is what I have so far, tell me if I'm over complicating this if so.

XNamespace z = "#RowsetSchema";
string lId = this.GetListID("Account");
string vId = this.GetViewID("All Documents", lId);
//this below, works, I'm getting the unique ID of folder...
string folderId = this.GetListData(lId, vId).Descendants(z + "row").
            Where(x => x.Attribute("ows_LinkFilename").Value.Equals("FolderName")).
            Select(x => x.Attribute("ows_UniqueId").Value).SingleOrDefault().ToString();    

private string GetListID(string listName)
{
    string listID;

    try
    {
        XDocument doc = XDocument.Parse(_listClient.GetListCollection().ToString());
                listID = (from x in doc.Elements().First().Elements()
                          where x.Attribute("Title").Value.Equals(listName)
                          select x.Attribute("ID").Value).FirstOrDefault();
    }
    catch
    {
        throw;
    }

    return listID;
}

private string GetViewID(string viewName, string listID)
{
    string viewID = null;

    try
    {
        XDocument doc = XDocument.Parse(_viewClient.GetViewCollection(listID).ToString());
            viewID = (from x in doc.Elements().First().Elements()
                      where x.Attribute("DisplayName").Value.Equals(viewName)
                      select x.Attribute("Name").Value).FirstOrDefault();

     }
     catch
     {
            throw;
     }

     return viewID;
}

 private XDocument GetListData(string listID, string viewID)
 {
     XDocument list_data = null;

     try
     {
            list_data = XDocument.Parse(_listClient.GetListItems(listID, viewID, null, null, "10000", null, null).ToString());
            var q = (from x in list_data.Elements().First().Elements().First().Elements()
                     select new
                    {
                        Title = x.Attribute("ows_LinkTitle").Value,
                        Field1 = x.Attribute("ows_Field1").Value,
                        Field2 = x.Attribute("ows_Field2").Value
                    });
     }
     catch
     {
         throw;  
     }


    return list_data;
}

As you can see, I'm able to get the unique ID of the folder in question. But then what? Is there any other SharePoint web service I need to use with the folder ID to get its contents ?

Here is an example of the structure of the URL for which I'm trying to get the contents of:

https://spsite.domain.ca/testenv/account/000001

The code above retrieves me the unique ID for the folder 000001 but then I'm stuck there... I don't see any GetFolderItems or something like that in lists.asmx or other SP web services.

I saw some examples out there but they use the assembly Microsoft.Sharepoint.dll to do so, which I'm trying to avoid.

Thank you!

1

1 Answers

0
votes

I will be using Microsoft.Sharepoint.Client for this. I had no idea SP2010+ offered such a feature.