ViewCollection class
SharePoint Online
Specifies a collection of list views.
System.Object
Microsoft.SharePoint.Client.ClientObject
Microsoft.SharePoint.Client.ClientObjectCollection
Microsoft.SharePoint.Client.ClientObjectCollection<View>
Microsoft.SharePoint.Client.ViewCollection
Microsoft.SharePoint.Client.ClientObject
Microsoft.SharePoint.Client.ClientObjectCollection
Microsoft.SharePoint.Client.ClientObjectCollection<View>
Microsoft.SharePoint.Client.ViewCollection
Namespace: Microsoft.SharePoint.Client
Assembly: Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)
Use the Views property of either the List or View class to return the collection of views for a list or the parent collection of views for a view. Use an indexer to return a single view from a collection of views. For example, if the collection is assigned to a variable named collViews, use collViews[index] in C#, or collViews(index) in Visual Basic, where index is the index number of the view in the collection, the name of the view, or the GUID for the view.
This code example adds a new view to the Tasks list of the specified site, and displays the list’s current views.
using System; using Microsoft.SharePoint.Client; namespace Microsoft.SDK.SharePointFoundation.Samples { class ViewCollectionExample { static void Main() { string siteUrl = "http://MyServer/sites/MySiteCollection"; ClientContext clientContext = new ClientContext(siteUrl); Web site = clientContext.Web; List targetList = site.Lists.GetByTitle("Tasks"); ViewCollection collView = targetList.Views; ViewCreationInformation viewInfo = new ViewCreationInformation(); viewInfo.Title = "MyView"; collView.Add(viewInfo); clientContext.Load(collView); clientContext.ExecuteQuery(); Console.WriteLine("Tasks list current views:\n\n"); foreach (View oneView in collView) Console.WriteLine(oneView.Title); } } }
Show: