2017-10-26 22 views
0

サイトの列をドキュメントライブラリの既定のビューに追加し、リスト自体をクリックすると表示/表示されるようにします。しかし、私はこれを行う方法については不明です。私が持っているコードは、これまでSharePoint Online - 既定のビューで列を表示/表示

// 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(); 

あなたは下の画像ファイルを見れば、私は基本的に上記のフィールドをtrueに「表示」のチェックボックスをチェックすることができるようにしたいです。

Edit view Screen - display columns

誰かが正しい方向に私を指すことができますか?あなたは、変更を永続化するために、再びclientContext.ExecuteQuery()を実行する必要が

おかげ

答えて

1

。また、オブジェクトをロードするために2回行う必要はなく、必要なものをすべてロードしてからサーバーから取得する必要はありません。

//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(); 
+0

ありがとうございます。 – user3428422

関連する問題