WSS3SDK之:在网站集中给用户界面添加操作

来源:互联网 发布:剑三二小姐脸型数据 编辑:程序博客网 时间:2024/06/01 18:14

Feature使得添加操作到Windows SharePoint Services用户界面的菜单变得更容易。下面的例子展示了如何通过Feature在各种菜单中添加操作,并实际的部署和激活它。

Location和Group ID

在为特定的菜单定义自定义操作前,您必须通过设置其区域信息为适当的WSS命名空间,并使用WSS用于标识特定区域的ID来标识该菜单。。

举个例子,如果要添加一个自定义操作到网站设置页面,需要设置CustomActionLocation 属性为Microsoft.SharePoint.SiteSettings。然后,通过GroupId 属性指定该页面的特定区域。

不同的操作可能需要使用不同的CustomAction属性来标识放置自定义操作的菜单。但是您可能还需要为该操作指定其他参数,比如,指定一个版本号,执行该操作的用户权限要求,或者与已有操作在菜单中的前后关系等。下面的自定义操作例子展示了各种的属性。

URL Tokens

WSS支持下列可用于相对URL地址前的记号:

~site - 网站(SPWeb)相对链接。

~sitecollection - 网站集(SPSite)相对链接。

同时,您还可以在URL中使用下列记号:

{ItemId} - 整数 ID 代表了列表中的列表项。

{ItemUrl} - 受控列表项的URL 。仅用于库中的文档。 [在Beta 2中无效]

{ListId} - 代表该列表的GUID。

{SiteUrl} - 网站URL (SPWeb).

{RecurrenceId} - 重复项ID。该记号不可以用于列表项的上下文菜单。

步骤

  1. C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES下创建一个 UserInterfaceLightUp 文件夹.

  2. 在新建的UserInterfaceLightUp文件夹中创建一个 Feature.xml 文件来提供该Feature的元素清单,如下所示:

    <?xml version="1.0" encoding="utf-8" ?>
    <Feature Id="GUID"
    Title
    ="Light Up"
    Description
    ="This example shows how you can light up various areas inside Windows SharePoint Services."
    Version
    ="1.0.0.0"
    Scope
    ="Site"
    xmlns
    ="http://schemas.microsoft.com/sharepoint/">
    <ElementManifests>
    <ElementManifest Location="Lightup.xml" />
    </ElementManifests>
    </Feature>
  3. 通过运行guidgen.exe(位于Local_Drive:/Program Files/Microsoft Visual Studio 8/Common7/Tools目录中)生成一个GUID来替换上面的 GUID 占位符。

  4. 创建一个LightUp.xml文件来定义Feature中的各种元素。为了在例子中展示效果,每个操作的URL将指向一个.aspx文件,并传给它一个表示请求来源的值,如下所示:

    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Document Library Toolbar New Menu Dropdown -->
    <CustomAction Id="UserInterfaceLightUp.DocLibNewToolbar"
    RegistrationType
    ="List"
    RegistrationId
    ="101"
    GroupId
    ="NewMenu"
    Rights
    ="ManagePermissions"
    Location
    ="Microsoft.SharePoint.StandardMenu"
    Sequence
    ="1000"
    Title
    ="MY DOCLIB NEW MENU TOOLBAR BUTTON">
    <UrlAction Url="/_layouts/LightupHello.aspx?NewMenu"/>
    </CustomAction>
    <!-- Document Library Toolbar Upload Menu Dropdown -->
    <CustomAction Id="UserInterfaceLightUp.DocLibUploadToolbar"
    RegistrationType
    ="List"
    RegistrationId
    ="101"
    GroupId
    ="UploadMenu"
    Rights
    ="ManagePermissions"
    Location
    ="Microsoft.SharePoint.StandardMenu"
    Sequence
    ="1000"
    Title
    ="MY DOCLIB UPLOAD MENU TOOLBAR BUTTON">
    <UrlAction Url="/_layouts/LightupHello.aspx?UploadMenu"/>
    </CustomAction>
    <!-- Document Library Toolbar Actions Menu Dropdown -->
    <CustomAction Id="UserInterfaceLightUp.DocLibActionsToolbar"
    RegistrationType
    ="List"
    RegistrationId
    ="101"
    GroupId
    ="ActionsMenu"
    Location
    ="Microsoft.SharePoint.StandardMenu"
    Sequence
    ="1000"
    Title
    ="MY DOCLIB ACTIONS MENU TOOLBAR BUTTON">
    <UrlAction Url="/_layouts/LightupHello.aspx?ActionsMenu"/>
    </CustomAction>
    <!-- Document Library Toolbar Settings Menu Dropdown -->
    <CustomAction Id="UserInterfaceLightUp.DocLibSettingsToolbar"
    RegistrationType
    ="List"
    RegistrationId
    ="101"
    GroupId
    ="SettingsMenu"
    Location
    ="Microsoft.SharePoint.StandardMenu"
    Sequence
    ="1000"
    Title
    ="MY DOCLIB SETTINGS MENU TOOLBAR BUTTON">
    <UrlAction Url="/_layouts/LightupHello.aspx?SettingsMenu"/>
    </CustomAction>
    <!-- Site Actions Dropdown -->
    <CustomAction Id="UserInterfaceLightUp.SiteActionsToolbar"
    GroupId
    ="SiteActions"
    Location
    ="Microsoft.SharePoint.StandardMenu"
    Sequence
    ="1000"
    Title
    ="MY SITE ACTIONS BUTTON">
    <UrlAction Url="/_layouts/LightupHello.aspx?SiteActions"/>
    </CustomAction>
    <!-- Per Item Dropdown (ECB)-->
    <CustomAction
    Id="UserInterfaceLightUp.ECBItemToolbar"
    RegistrationType
    ="List"
    RegistrationId
    ="101"
    Type
    ="ECBItem"
    Location
    ="EditControlBlock"
    Sequence
    ="106"
    Title
    ="MY ECB ITEM">
    <UrlAction Url="/_layouts/LightupHello.aspx?ECBItem"/>
    </CustomAction>
    <!-- Display Form Toolbar -->
    <CustomAction
    Id="UserInterfaceLightUp.DisplayFormToolbar"
    RegistrationType
    ="List"
    RegistrationId
    ="101"
    Location
    ="DisplayFormToolbar"
    Sequence
    ="106"
    Title
    ="MY DISPLAY FORM TOOLBAR">
    <UrlAction Url="/_layouts/LightupHello.aspx?DisplayFormToolbar"/>
    </CustomAction>
    <!-- Edit Form Toolbar -->
    <CustomAction
    Id="UserInterfaceLightUp.EditFormToolbar"
    RegistrationType
    ="List"
    RegistrationId
    ="101"
    Location
    ="EditFormToolbar"
    Sequence
    ="106"
    Title
    ="MY EDIT FORM TOOLBAR">
    <UrlAction Url="/_layouts/LightupHello.aspx?EditFormToolbar"/>
    </CustomAction>
    <!-- Site Settings -->
    <CustomAction
    Id="UserInterfaceLightUp.SiteSettings"
    GroupId
    ="Customization"
    Location
    ="Microsoft.SharePoint.SiteSettings"
    Sequence
    ="106"
    Title
    ="MY SITE SETTINGS LINK">
    <UrlAction Url="/_layouts/LightupHello.aspx?Customization"/>
    </CustomAction>
    <!-- Content Type Settings -->
    <CustomAction
    Id="UserInterfaceLightUp.ContentTypeSettings"
    GroupId
    ="General"
    Location
    ="Microsoft.SharePoint.ContentTypeSettings"
    Sequence
    ="106"
    Title
    ="MY CONTENT TYPE SETTINGS LINK">
    <UrlAction Url="/_layouts/LightupHello.aspx?General"/>
    </CustomAction>
    </Elements>

    其他一些常用的 GroupId 值包括 ViewToolbar, ViewSelectorMenu, 和 PersonalActions (Welcome 菜单)

  5. /TEMPLATE/LAYOUTS目录中添加一个 LightupHello.aspx 文件来定位上一步中创建的那些链接。

    <%@ Page Language="C#" Inherits="System.Web.UI.Page"%>
    <%
    string clientQuery = Page.ClientQueryString;
    if (clientQuery == "NewMenu")
    {
    Response.Write(
    "您来自新建文档菜单。");
    }
    else if (clientQuery == "UploadMenu")
    {
    Response.Write(
    "您来自上载文档菜单。");
    }
    else if (clientQuery == "ActionsMenu")
    {
    Response.Write(
    "您来自操作菜单。");
    }
    else if (clientQuery == "SettingsMenu")
    {
    Response.Write(
    "您来自设置菜单。");
    }
    else if (clientQuery == "SiteActions")
    {
    Response.Write(
    "您来自网站操作菜单。");
    }
    else if (clientQuery == "ECBItem")
    {
    Response.Write(
    "您来自文档的上下文菜单。");
    }
    else if (clientQuery == "DisplayFormToolbar")
    {
    Response.Write(
    "您来自显示列表项属性的窗体。");
    }
    else if (clientQuery == "EditFormToolbar")
    {
    Response.Write(
    "您来自编辑列表项属性的窗体。");
    }
    else if (clientQuery == "Customization")
    {
    Response.Write(
    "您来自网站设置菜单。");
    }
    else if (clientQuery.StartsWith("General"))
    {
    Response.Write(
    "您来自内容类型设置菜单。");
    }
    %>
  6. 进入命令行,输入下列命令来安装Feature,并在特定子站点上将其激活,然后重启IIS( Microsoft Internet Information Services )使变更生效。
    a. stsadm -o installfeature -filename UserInterfaceLightUp/feature.xml
    b. stsadm -o activatefeature -filename UserInterfaceLightUp/feature.xml -url http://Server/Site/Subsite
    c. iisreset

  7. 想要查看您添加的各种自定义操作,从主页导航到对应网站的下列位置:

    1. 点击网站操作,查看新增的自定义操作
    2. 点击网站操作中的网站设置,进入网站设置页面,查看新增的自定义操作。

    3. 导航到一个文档库,分别打开工具栏上的每个菜单,查看新增的自定义操作。

    4. 在一个包含内容的文档库中,点击列表项的下箭头,查看新增的自定义操作。

    5. 点击查看属性编辑属性进入显示窗体和编辑窗体,查看工具栏中新增的自定义操作。

原创粉丝点击