Sunday, 19 April 2015

The property or field 'Title' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.



Usually we get this error when we try to use a property before calling ExecuteQuery(); 


                  clientContext.Load(ItemCollection);
                clientContext.ExecuteQuery();
                if (ItemCollection!= null && ItemCollection.Count > 0)
                {
                    item= ItemCollection[0];                   
               }
when i try to get the field "Manager" i.e item["Manager"] i was getting the above error, so i modified the code as below:

       clientContext.Load(ItemCollection);
                clientContext.ExecuteQuery();
                if (ItemCollection!= null && ItemCollection.Count > 0)
                {
                    item= ItemCollection[0];           
                    clientContext.Load(item);
                    clientContext.ExecuteQuery();        
               }

then its worked fine.

Wednesday, 1 April 2015

1) How to get the Web Title in Sharepoint 2013 using CSOM.

sharePointURL = new Uri(Request.QueryString["SPHostUrl"]);

 using (var clientContext =SolutionName.TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWeb, null))
{


Web oWebsite = clientContext.Web;
                clientContext.Load(clientContext.Web, web => web.Url);
                clientContext.ExecuteQuery();
               string  webURL = clientContext.Web.Url;

}