ViewCollection class

Specifies a collection of list views.

Inheritance hierarchy


Namespace:  Microsoft.SharePoint.Client
Assembly:  Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)


Public Class ViewCollection _
    Inherits ClientObjectCollection(Of View)
Dim instance As ViewCollection
public class ViewCollection : ClientObjectCollection<View>


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";


            Console.WriteLine("Tasks list current views:\n\n");
            foreach (View oneView in collView)

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also


ViewCollection members

Microsoft.SharePoint.Client namespace