Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
        clientContext.Load(collListItem);
        clientContext.ExecuteQuery();

        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()));
            tv_AppData.Nodes.Add(tn);
        }

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

1 Answer 1

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

 
discard

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.