I am working on a project where the ClientContext might be active for a long time. To prevent memory usage getting out of hand I would like to use
ClientContext.LoadQuery() instead of
ClientContext.Load() when getting items from SharePoint.
LoadQuery works very well when loading lists of items such as
Web.Webs but I haven't found a way to load a single object such as
ClientContext.Web. Loading a single website with
Load() I would use the following:
string relativeUrl = "/mysite"; Web web = ctx.Site.OpenWebUsingPath( relativeUrl ); ctx.Load(web, w => w.Title); ctx.ExecuteQuery();
LoadQuery() I had hoped I could do something like
string relativeUrl = "/mysite"; Web tmpWeb = ctx.Site.OpenWebUsingPath( relativeUrl ); Web web = ctx.LoadQuery(tmpWeb, w => w.Title); ctx.ExecuteQuery();
That is not possible since
LoadQuery takes either
ClientObjectCollection<T> as input.
Is there any way to get the web object without having it bound to to the client context and using unnecessary memory?