Thursday, May 7, 2015

Invalid data has been used to update the list item. The field you are trying to update may be read only | The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested

Issue1: Invalid data has been used to update the list item. The field you are trying to update may be read only.

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

Problem Code:
internal static Void GetFileFromTempDocLib(ClientContext clientContext1)  
{
                var folderRelativeUrl = "";
                Web web = clientContext.Web;                
                clientContext.Load(web, w1 => w1.ServerRelativeUrl, w1 => w1.Url);
                clientContext.ExecuteQuery();
                folderRelativeUrl = web.ServerRelativeUrl;

}

Solution Code:
internal static Void GetFileFromTempDocLib(ClientContext clientContext1)  
{
                var folderRelativeUrl = "";
                Web web = clientContext.Web;
                try
                {
                    folderRelativeUrl = web.ServerRelativeUrl;
                }
                catch (PropertyOrFieldNotInitializedException ex)
                {
                    clientContext.Load(web, w1 => w1.ServerRelativeUrl, w1 => w1.Url);
                    clientContext.ExecuteQuery();
                    folderRelativeUrl = web.ServerRelativeUrl;
                }
}

1 comment:

Featured Post

Pin a SharePoint Site to the Microsoft Teams Left Rail (No Code)

This is a no-code, step-by-step guide. You package a SharePoint page as a Teams app, upload it, and pin it for everyone in your organisation...

Popular posts