我正在将一个站点列添加到文档库的默认视图中,并希望当您单击列表本身时它可见/显示。但是,我不确定如何做到这一点。我到目前为止的代码
// 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();
如果您查看下面的图片文件,我基本上希望能够检查上述字段的“显示”复选框为真。
有人能指出我正确的方向吗?
由于
答案 0 :(得分:1)
您需要再次执行clientContext.ExecuteQuery()
以保留更改。此外,没有必要两次加载您的对象,加载您需要的一切,然后从服务器获取它:
//Put following line in the using section
using Microsoft.SharePoint.Client;
//Your code
View v = Employeecvlist.GetViewByName("All Documents");
Field name = Employeecvlist.Fields.GetByInternalNameOrTitle("Name");
clientContext.Load(v, x => x.ViewFields);
clientContext.Load(name);
v.ViewFields.Add(name.InternalName);
v.Update();
clientContext.ExecuteQuery();