SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an application that I built using the Managed Client Object model that performaing poorly and I am curious if I am doing something wrong. The application drills down throw a hierarchy of three parent/child lists. The code I use to access the correct list items at each level looks like this with different list names and slightly different logic:

        ClientContext clientContext = new ClientContext(siteUrl);
        SP.List oList = clientContext.Web.Lists.GetByTitle("Application Inventory");
        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml = "<View><RowLimit>100</RowLimit><Query><OrderBy><FieldRef Name='Title'/></OrderyBy></Query></View>";
        SP.ListItemCollection collListItem = oList.GetItems(camlQuery);

        foreach (SP.ListItem oListItem in collListItem.ToList<SP.ListItem>())
                          //this gets the second level of the hierarchy
            TreeNode tn = GetAppSolutions(Convert.ToInt32(oListItem["ID"]), new TreeNode(oListItem["Title"].ToString()));

My issue is that this code takes about a minute to run and render my ASP.NET treeview. Can anyone see something that I am doing here that could cause this to happen?

As you may be able to see from the above code I am looping through each item in the parent list and making calls to SharePoint for each item to get it's child items. Could this be the problem?

share|improve this question
up vote 1 down vote accepted

I'm assuming GetAppSolutions() is your own homegrown function, in which case it also looks like you are not passing the clientContext into it, which means that it must be creating a new context for every item in the list, which can be a huge performance hit. Try passing the clientContext, olist and whatever else makes sense to the GetAppSolutions() routine so that you are not constantly refetching the same data over and over.

I would also store the return value of collListItem.ToList() in a variable and then iterating through the variable instead. SharePoint has been known to rebuild entire collections when iterating through them in the manner you have listed.

share|improve this answer
+1, that sped it way up thank you! Unfortunately it's still running pretty slow (about 18 seconds for the page to load). I did a profiling report and it looks like about 85% of that is spend on the ExecuteQuery portion of my code in the second level. That would be inside the GetAppSolutions method that I custom wrote. This particular ExecuteQuery is called bout 80 times. Am I just expecting too much from the Client Object Model? – Abe Miessler Oct 24 '11 at 23:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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