共用方式為


UserCustomActionCollection.Add 方法

加入集合中的新UserCustomAction自訂動作。

命名空間:  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 As UserCustomAction
'用途
Dim instance As UserCustomActionCollection
Dim returnValue As UserCustomAction

returnValue = instance.Add()
public UserCustomAction Add()

傳回值

類型:Microsoft.SharePoint.Client.UserCustomAction
傳回代表新的自訂動作至集合UserCustomAction執行個體。

例外狀況

例外狀況 條件
UnauthorizedAccessException

目前的使用者沒有權限執行的作業。錯誤碼 ︰-2147024891。

範例

本程式碼範例會加入指定網站的 [網站動作] 功能表中的新功能表項目。

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
{
    class UserCustomActionCollection_AddExample
    {
        static void Main()
        {
            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            Web site = clientContext.Web;

            UserCustomActionCollection collUCA = site.UserCustomActions;
            UserCustomAction newUCA = collUCA.Add();
            newUCA.Location = "Microsoft.SharePoint.StandardMenu";
            newUCA.Group = "SiteActions";
            newUCA.Sequence = 1000;
            newUCA.Title = "New Menu Item";
            newUCA.ImageUrl = "/_layouts/images/myIcon.jpg";
            newUCA.Description = "Menu item added";
            newUCA.Url = "/_layouts/create.aspx";
            newUCA.Update();

            clientContext.ExecuteQuery();

            Console.WriteLine("New menu item added to Site Actions menu.\n\nTo view the new menu item, refresh the page.");
        }
    }
}

請參閱

參照

UserCustomActionCollection 類別

UserCustomActionCollection 成員

Microsoft.SharePoint.Client 命名空間