Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

More efficient way of getting list details in C#?

$
0
0

Hi,

I have a sharepoint provider hosted app with the following code, the app works fine the way it is but I am experiencing issues with the server returning "429 - Too many requests" and to try and get around the problem I am revisiting my code to see if I can find more efficient ways of running it. Does anyone know how I can perform the following without having to run "clientContext.ExecuteQuery()" in the "foreach" statement?

 // Get all lists
                ListCollection lists = clientContext.Web.Lists;
                clientContext.Load<ListCollection>(lists);
                clientContext.ExecuteQuery();

// Get sharepoint url without trailing backslash
                string sharepointUrlNoBackSlash = VirtualPathUtility.RemoveTrailingSlash(sharepointUrl.ToString());

// Loop through lists
                foreach (List list in lists)
                {
                    clientContext.Load(list, l => l.DefaultViewUrl, l => l.EffectiveBasePermissions, l => l.ImageUrl);
                    clientContext.ExecuteQuery();

// If list is specified in list ids and user has permission to view list
                    if (listIdGuids.Contains(list.Id) && list.EffectiveBasePermissions.Has(PermissionKind.ViewListItems))
                    {
// Create document library object
                        SharepointList dl = new SharepointList();
                        dl.Title = list.Title;
                        dl.DefaultViewUrl = sharepointUrlNoBackSlash + list.DefaultViewUrl;

// Add to list
                        documentLibraries.Add(dl);
                    }

                }


Impreza Software Development


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>