0

i want to get items in android via web api web service.

when user click on items web api return values step by step from sharepoint task list.

        using (ClientContext context = new ClientContext(siteUrl))
        {
            context.Credentials = new NetworkCredential(user, password, shp.domainname);

            //SP.List oList = context.Web.Lists.GetByTitle(id);
            Web web = context.Web;
            List list = web.Lists.GetByTitle(listname);
            context.Load(list);
            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View Scope=\"Recursive\"><RowLimit></RowLimit>/View>";
            //camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"><RowLimit></RowLimit>/View>";
            ListItemCollection items = list.GetItems(camlQuery);
            context.Load(items);
            try
            {
                context.ExecuteQuery();
            }
            catch (Exception e1)
            {
                //some code here
            }

            foreach (ListItem item in items)
            {
                AndroidReport andRep = new AndroidReport();

                andRep.id = int.Parse(item["ID"].ToString());
                andRep.title = item["Title"].ToString();
                andRep.rootlevel = int.Parse(item["_Level"].ToString());
                int a = int.Parse(item["ItemChildCount"].ToString());
                int b = int.Parse(item["FolderChildCount"].ToString());
                if(a>b)
                    andRep.FolderChildCount = a;
                else
                    andRep.FolderChildCount = b;
                //note
                //todo: r1 when subfolder in data downsn exist
                if (andRep.FolderChildCount >= 0)
                    andRep.type = "true";

                andReps.Add(andRep);
            }

but problem is which way to get only items (folders) on specific folder... not all the folders and items...

i want to get only the folders on root folder...

when i query

        camlQuery.ViewXml = "<View Scope=\"Recursive\"><RowLimit></RowLimit>/View>";

only leaf appears

and when this query:

        camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"><RowLimit></RowLimit>/View>";

all the childs and parents returned.

thanks in advanced

0

1 Answer 1

1

For getting items in a specific folder, you can specify the SPQuery.Folder

Following example should help:

SPFolder folder = web.GetFolder("/Docs/folder1");
if(folder.ItemCount > 0)
{
  SPList list = web.Lists.TryGetList("ListName");
  SPQuery query = new SPQuery();
  query.Folder = folder;
  SPListItemCollection collListItems = list.GetItems(query);
}
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.