zoukankan      html  css  js  c++  java
  • Custom Actions in WSS 3 / MOSS 2007 Part 1

    Custom Actions in WSS 3 / MOSS 2007 - Part 1

    Something that really frustrates my about WSS 3 and MOSS 2007 is the lack of documentation on alot of the object model as well as some of the CAML. One of the areas that really wasn't very helpful at all was the section on custom actions, so I thought I would write this post.

    To begin with, just a quick introduction...custom actions in SharePoint simply refer to the buttons (such as in the "Site Actions" menu) and some of the menus across the site (such as in "Site Settings"). The best way to deploy these custom actions is definitley through a Feature. This post will show the simple way to display these custom actions. In the next post I will show how to use custom controls for the menu buttons.

    Anyways, onto the code (or XML in this case)!

    In the first example, I will create a custom action for the "Site Actions" menu.
    To do this (and for the sake of the rest of the examples) we will begin with creating our feature manifest. Here it is:


    <?xml version="1.0" encoding="utf-8"?>
    <Feature Id="65245A4A-5D65-45ea-896F-6A6A808F3C80"
    Title="MyCustomActionFeature"
    Description="This feature adds custom actions"
    Version="1.0.0.0"
    Scope="Site"
    xmlns="http://schemas.microsoft.com/sharepoint/">
    <ElementManifests>
    <ElementManifest Location="MyCustomActions.xml"/>
    </ElementManifests>
    </Feature>

    Here is what the MyCustomActions.xml file looks like to add an extra item to the Site Actions menu (Note that in most of the examples below, I have just left the Url blank because these are just examples, but this would be where you put the Url of where you want to link to):


    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
    Id="PeopleAndGroupsAction"
    GroupId="SiteActions"
    Location="Microsoft.SharePoint.StandardMenu"
    Sequence="10"
    Title="People and Groups"
    ImageUrl="/_layouts/images/Actionscreate.gif">
    <UrlAction
    Url="/_layouts/people.aspx" />
    </CustomAction>
    </Elements>

    Here is what the MyCustomActions.xml file looks like to add another custom actions menu item to the Actions menu of a list or document library.


    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
    Id="MyListActionsCustomAction"
    GroupId="ActionsMenu"
    Location="Microsoft.SharePoint.StandardMenu"
    RegistrationType="List"
    Sequence="10"
    Title="My Actions Custom Action">
    <UrlAction
    Url="~site" />
    </CustomAction>
    </Elements>

    Here is what the MyCustomActions.xml file looks like to add another section to the Site Settings page.


    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomActionGroup
    Id="NewSiteSettingsGroup"
    Location="Microsoft.SharePoint.SiteSettings"
    Title="New Site Settings Group"
    Sequence="10"
    Description="" />
    <CustomAction
    Id="NewSiteSettingsGroupItem"
    GroupId="NewSiteSettingsGroup"
    Location="Microsoft.SharePoint.SiteSettings"
    Sequence="10"
    Title="My New Site Settings Item">
    <UrlAction
    Url="~site" />
    </CustomAction>
    </Elements>

    Here is what the MyCustomActions.xml file looks like to add another section and custom action to the Central Administration page.


    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomActionGroup
    Id="CustomCentralAdminSection"
    Location="Microsoft.SharePoint.Administration.ApplicationManagement"
    Title="Custom Central Admin Section"
    Sequence="10" />
    <CustomAction
    Id="DoSomethingInCentralAdmin"
    GroupId="CustomCentralAdminSection"
    Location="Microsoft.SharePoint.Administration.ApplicationManagement"
    Sequence="10"
    Title="Do Something In Central Admin">
    <UrlAction
    Url="" />
    </CustomAction>
    </Elements>

    As you can see, adding these actions is very easy. If you want to add a group like in the Site Settings and Central Admin examples, all you have to do is add the CustomActionGroup element and then use that ID for the GroupID in your CustomAction element.

    There are also attributes such as RequiresSiteAdministrator and Rights which all some security trimming.

    Also, if you are trying to find the appropriate value for the Location attribute, or GroupID attribute, there are a few listed in the SDK documentation. If you want more, you can simply look/search through the "Features" directory (%Program Files%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\) for the CustomActions written by Microsoft. After all, they used the same method Ive shown above for alot of the menus and buttons you see.

    Anyway, I hope you have got the idea of custom actions. In one of the posts I have coming up I will show how to use custom controls (and hence use the ControlAssembly and ControlClass attributes) to render your custom actions.

  • 相关阅读:
    Django学习笔记(16)——扩展Django自带User模型,实现用户注册与登录
    Django学习笔记(15)——中间件
    JAVA—API和SPI概念
    mybatis 映射器(mappers) 配置说明 加载映射文件方式
    Java的三种代理模式
    如何选择分布式事务形态(TCC,SAGA,2PC,补偿,基于消息最终一致性等等)
    什么是分布式系统中的幂等性
    js date 前一天
    getCanonicalFile与getAbsoluteFile区别
    Mybatis 示例之 SelectKey
  • 原文地址:https://www.cnblogs.com/icedog/p/1772526.html
Copyright © 2011-2022 走看看