我的人生乐园>>Enjoying Myslef!

写好博客,天天向上!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MOSS 2007 应用随笔(2)--自定义moss菜单汇总(二)

Posted on 2008-05-11 14:13  乐土  阅读(382)  评论(0编辑  收藏  举报
这个菜单是用Feature部署上去的功能,先提一下Feature的作用:
微软在MOSS中利用Feature的特性,可以将Feature.xml中以特定格式描述的功能部署到MOSS中,这些功能包括工作流,菜单项,网站栏、内容类型...等等。然后可以在MOSS中配置启用或者停用这些功能,由于这个特性不需要进行代码开发,只需要配置Feature.xml和其中指定的另一个xml,方法简单可行。
Feature.xml如下:
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="6098EC11-8128-409A-8D2C-414E93F67DD4"
 
            Title="add my menu"
 
            Description="this is a custom menu"
 
            Version="1.0.0.0"
 
            Scope="Site"
 
            Hidden="FALSE"
 
            DefaultResourceFile="customDocumentLibrary"
 
            xmlns="http://schemas.microsoft.com/sharepoint/">
 
            <ElementManifests>
 
                <ElementManifest Location="elements.xml" />
 
            </ElementManifests>
 
</Feature>
 
解释一下其中的内容,Id是GUID类型标示的唯一值,可以由VS自带的GUID Generator来生成,Tiltle是功能标题,Version是版本号,Description:对description的描述,Scope:其值可以是Web或Site,它指明了这个Feature是应用于整个的Site Collection还是仅仅用于单独的一个子站点。Hidden:值可以是True或False.该设置指定了这个Feature是否在Site Feature页面上显示。DefaultResourceFile: 资源文件名字,Feature依赖它提供其它附加的配置信息。
Feature.xml文件中的<ElementManifests>元素,这个元素包含了另一个XML文件的位置,而这个文件包含的<Elemnets>的内容是Feature要实现的。
<ElementManifest>元素指明了要使用一个名为ProvisionedFiles.xml的文件,以下是该文件的<Elements>元素内容。
下面是Feature.xml中指定的elements.xml内容:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <!-- create command link site setting page -->
 <CustomAction Id="SiteSettings" GroupId="Customization"
                Location="Microsoft.SharePoint.SiteSettings"
                            Sequence="106"
                            Title="Custom Litware Site Setting Command">
                            <UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=SiteSettingCommand"/>
     </CustomAction>
     <!-- Add command to site action dropdow -->
        <CustomAction Id="SiteActionsToolbar111111111111"
 
                       GroupId="SiteActions"
                                   Location="Microsoft.SharePoint.StandardMenu"
                                   Sequence="1000"
                                   Title="Litware custom Action"
                                   Description="custom litware site action"
                                   ImageUrl="/_layouts/images/ACL16.GIF">
                                   <UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=SiteActionCommand"/>
    </CustomAction>
       <!-- Document Library Toolbar New Menu DropDown -->
       <CustomAction Id="DocLibNewToolbar"
               RegistrationType="List"
                     RegistrationId="101"
                     GroupId="NewMenu"
                     Rights="ManagePermissions"
                     Location="Microsoft.SharePoint.StandardMenu"
                     Sequence="1000"
                     Title="Litware Custom New Command"
                     Description="THis Command Creates a new Litware doc"
                     ImageUrl="/_layouts/images/ACL16.GIF">
                     <UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=NewDocCommand"/>
    </CustomAction>
       <!-- Document library Toolbar Actions Menu Dropdown -->
       <CustomAction  Id="DocLibActionsToolbar"
               RegistrationType="List"
                     RegistrationId="101"
                     GroupId="ActionsMenu"
                     Rights="ManagePermissions"
                     Location="Microsoft.SharePoint.StandardMenu"
                     Sequence="1000"
                     Title="Litware Command on Document Library"
                     Description="THis Command Creates a new Litware doc"
                     ImageUrl="/_layouts/images/ACL16.GIF">
                     <UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=DocLibCommand"/>
         </CustomAction>
         <CustomAction Id="ECBItemToolbar"
               RegistrationType="List"
                     RegistrationId="101"
                     Type="ECBItem"
                     Location="BugWorkaround:LocationShouldEqualEditControlBlock"
                     Sequence="106"
                     Title="Litware ECB item Command">
                     <UrlAction Url="/_layouts/litwarefeaturelab.aspx?command=SiteSettingCommand"/>
         </CustomAction>
</Elements>
其中第一个CustomActionSite Setting页面中的LOOK AND FEEL标题下创建了一个自定义链接.第二个CustomAction在页面的Site Action菜单下增加了一个用户自定义菜单项.第三个CustomAction在文档库的New下拉菜单下创建了一个自定义菜单项.第四个CustomAction在文档库的Action下拉菜单下创建了一个自定义菜单项.
注意第五个CustomAction本来是在文档库的每个列表项的菜单上增加一个菜单项,但是不知什么原因不能正确加入,有待进一步的研究.
再做俩个批处理文件来部署和卸载这个Feature
部署批处理文件InstallFeature.bat
 
@rem======================================================================
@rem
@rem    InstallFeature.bat
@rem
@rem======================================================================
@echo off
setlocal
pushd .
goto InstallFeature

@rem----------------------------------------------------------------------
@rem   InstallFeature
@rem----------------------------------------------------------------------
:InstallFeature
    set SPAdminTool=%CommonProgramFiles%\Microsoft Shared\web server extensions\12\BIN\stsadm.exe
    set TargetUrl=http://huijianming
    set FeaturePath=menu\Feature.xml
  
    echo InstallFeature %FeaturePath%
    "%SPAdminTool%" -o installfeature -filename %FeaturePath% -force
    echo Activating feature %FeaturePath%
    "%SPAdminTool%" -o activatefeature -filename %FeaturePath% -url %TargetUrl% -force
    echo iisreset
    iisreset
 
卸载批处理文件UnInstallFeature.bat

@rem======================================================================
@rem
@rem    UnInstallFeature.bat
@rem
@rem======================================================================
@echo off
setlocal
pushd .
goto UnInstallFeature

@rem----------------------------------------------------------------------
@rem   UnInstallFeature
@rem----------------------------------------------------------------------
:InstallFeature
    set SPAdminTool=%CommonProgramFiles%\Microsoft Shared\web server extensions\12\BIN\stsadm.exe
    set TargetUrl=http://huijianming
    set FeaturePath=menu\Feature.xml
  
    echo InstallFeature %FeaturePath%
    "%SPAdminTool%" -o UnInstallFeature-filename %FeaturePath% -force
    echo iisreset
    iisreset

将以上的两个XML放到Menu的文件夹中,然后将文件夹拷贝到C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
运行部署批处理文件
 
效果图如下:
文档库新建菜单
文档库操作菜单
 
网站操作菜单
运行卸载批处理文件