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;
                }
}

No comments:

Post a Comment

Featured Post

Create SharePoint Folder Structure in Destination (Only If Not Exists)

Why This Script Is Safe You can run it multiple times It will not create duplicate folders It will only create missing folders S...

Popular posts