0

I'm updating site column with this code:

Field field = site.Fields.GetById(property.MappedSiteColumn);
clientContext.Load(field);

field.SchemaXml = xml;
clientContext.ExecuteQuery();

The site column in SharePoint change correctly.

enter image description here

But, when i search the files that content this site column with this code:

File file = site.GetFileByServerRelativeUrl(documentUrl);
ListItem item = file.ListItemAllFields;

clientContext.Load(file);
clientContext.Load(item);
clientContext.ExecuteQuery();
var fieldValues = item.FieldValues

The change in the Site Column is not refreshed in fieldValues variable. How can't i make this refresh?

0

When you are setting the SchemaXml of the field, you are setting it in the field that is in the Fields collection at the site level.

When fields are used in lists and libraries, a copy of the field is made and added to the Fields collection at the list level. In order for changes to the field at the site level to be pushed down to the field copies at the list level, you have to explicitly tell SharePoint to do that.

In the server side object model, what you would do would be to call SPField.Update(true).

Disclaimer - I have very little experience with the CSOM, however, it is my very strong suspicion that what you are going to need to do is call Field.UpdateAndPushChanges(true).

So your code would look something like

Field field = site.Fields.GetById(property.MappedSiteColumn);
clientContext.Load(field);

field.SchemaXml = xml;
field.UpdateAndPushChanges(true);
clientContext.ExecuteQuery();
1
  • Hi, thanks for answering, that code help me to refresh the site column in sharepoint file. But in C# code, when exect the code: File file = site.GetFileByServerRelativeUrl(documentUrl); ListItem item = file.ListItemAllFields; clientContext.Load(file); clientContext.Load(item); clientContext.ExecuteQuery(); var fieldValues = item.FieldValues; The key is the old. I'd appreciate your help.
    – Agustín
    Jul 24 '20 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.