次の方法で共有


ViewCollection class

Specifies a collection of list views.

Inheritance hierarchy

System.Object
  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)

Syntax

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

Remarks

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.

Examples

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); 
        }
    }
}

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

Reference

ViewCollection members

Microsoft.SharePoint.Client namespace