View class

Specifies a list view.

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.SharePoint.Client.View

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

Syntax

'Declaration
Public Class View _
    Inherits ClientObject
'Usage
Dim instance As View
public class View : ClientObject

Remarks

Use the DefaultView property of the List class to return the default view for a list, or the GetView() method to return a specified view. Use the GetViewFromUrl() method of the Web class to return a view for a list within a site, and use the View() property of the ViewFieldCollection class to get the parent view of the collection of view fields. Otherwise, use the Views property of the List 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 orders the items on the Tasks list of the specified site in descending alphabetic order.

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
{
    class ViewExample
    {
        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;
            View targetView = collView.GetByTitle("All Tasks");
            string strQuery = "<OrderBy><FieldRef Name=\'Title\' Ascending=\'False\' /></OrderBy>";
            targetView.ViewQuery = strQuery;
            targetView.Update();

            clientContext.ExecuteQuery();

            Console.WriteLine("Tasks list ordered in descending alphabetic order.");
        }
    }
}

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

View members

Microsoft.SharePoint.Client namespace