ViewCollection.Add 方法

Adds a new list view to the collection.

命名空间:  Microsoft.SharePoint.Client
程序集:   Microsoft.SharePoint.Client.Silverlight(位于 Microsoft.SharePoint.Client.Silverlight.dll 中);  Microsoft.SharePoint.Client.Phone(位于 Microsoft.SharePoint.Client.Phone.dll 中)  Microsoft.SharePoint.Client(位于 Microsoft.SharePoint.Client.dll 中)

语法

声明
Public Function Add ( _
    parameters As ViewCreationInformation _
) As View
用法
Dim instance As ViewCollection
Dim parameters As ViewCreationInformation
Dim returnValue As View

returnValue = instance.Add(parameters)
public View Add(
    ViewCreationInformation parameters
)

参数

返回值

类型:Microsoft.SharePoint.Client.View
Returns a View instance representing the addition of a new list view to the collection.

异常

异常 条件
[System.ArgumentException]

Field internal name for field is not in the list view. Error code: -2147024809.

[System.InvalidOperationException]

Type of the new list view is not allowed for the list. Error code: -1.

[System.IO.DirectoryNotFoundException]

List does not exist. Error code: -2147024893.

[System.UnauthorizedAccessException]

The current user has insufficient permissions. Error code: -2147024891.

备注

It must not be 空引用(无 在 Visual Basic 中).

示例

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

另请参阅

引用

ViewCollection 类

ViewCollection 成员

Microsoft.SharePoint.Client 命名空间