1

I am adding a site column into a document library default view and want it to be visible/shown when you click onto the list itself. However, I am unsure on how to do this. The code I have so far

// Get the view (this is the default view)  
Microsoft.SharePoint.Client.View v = Employeecvlist.GetViewByName("All Documents");

// Load it up
clientContext.Load(v, x => x.ViewFields);
clientContext.ExecuteQuery();

// Get the field I want to add to the view
Microsoft.SharePoint.Client.Field name = 
Employeecvlist.Fields.GetByInternalNameOrTitle("Name");

clientContext.Load(name);
clientContext.ExecuteQuery();

// Add this field to the view !! Nothing else in the view object to allow to make it visible by default !!
v.ViewFields.Add(name.InternalName);

// Finally, update the view
v.Update();

If you look at the image file below, I basically want to be able to check the "display" checkbox to true for the above field.

Edit view Screen - display columns

Can someone point me into the right direction?

Thanks

2

If this is the full code, so you just need to ExecuteQuery after v.Update(); to reflect the view update!

The final code should look like

Microsoft.SharePoint.Client.View v = Employeecvlist.GetViewByName("All Documents");
// Load it up
clientContext.Load(v, x => x.ViewFields);
// Get the field I want to add to the view
Microsoft.SharePoint.Client.Field name = 
Employeecvlist.Fields.GetByInternalNameOrTitle("Name");
clientContext.Load(name);
// Add this field to the view !! Nothing else in the view object to allow to make it visible by default !!
v.ViewFields.Add(name.InternalName);
// Finally, update  the view & excute!
v.Update();
clientContext.ExecuteQuery();

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.