一.自定义文档库/列表库中项目的右键关联菜单
原始菜单如下图所示:
下面开始我们本次的工作历程:
首先,找到C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS这个目录下的2052目录(这个默认是中文版本的路径,英文版本的MOSS是1033目录),其中有个core.js的JS文件,MS已经给我们预留了自定义的接口来实现我们自己的菜单定义了
添加以下两个JS的函数代码:
funtion AddListMenuItems(m,ctx)
{
if(typeof(Custom_AddListMenuItems) != "undefined")
{
if(Custom_AddListMenuItems(m,ctx))
return;
}
}
funtion AddDocLibMenuItems(m,ctx)
{
if(typeof(Custom_AddListMenuItems) != "undefined")
{
if(Custom_AddListMenuItems(m,ctx))
return;
}
}
然后我们实现自定义函数AddListMenuItems(列表库)和AddDocLibMenuItems(文档库)
,在页面右上角点击‘网站操作’--编辑网页--添加Webpart部件,选择
点击Webpart部件右边的‘编辑’--修改共享Webpart部件
在页面中点击‘源编辑器’
,在弹出的窗口中添加自定义函数AddListMenuItems(列表库)和AddDocLibMenuItems(文档库)
<script language="javascript">
function Custom_AddDocLibMenuItems(m, ctx)
{
strDisplayText = "报表统计";
var rootMenu = CASubM(m,strDisplayText,"","",500);
strDisplayText = "汇总表";
strAction = "STSNavigate('~site/_layouts/ItemAudit.aspx?ItemId={ItemId}&ListId={ListId}')";
strImagePath=ctx.imagesPath+"oisweb.gif";
menuOption = CAMOpt(rootMenu,strDisplayText,strAction,strImagePath);
menuOption.id = "ID_MySubMenu";
//var rootMenu = CASubM(m,strDisplayText,"","",500);
strDisplayText = "数字统计表";
strAction = "STSNavigate('~site/_layouts/ItemAudit.aspx?ItemId={ItemId}&ListId={ListId}')";
strImagePath=ctx.imagesPath+"oisweb.gif";
menuOption = CAMOpt(rootMenu,strDisplayText,strAction,strImagePath);
menuOption.id = "ID_MySubMenu";
strDisplayText = "行列汇总表";
strAction = "STSNavigate('~site/_layouts/ItemAudit.aspx?ItemId={ItemId}&ListId={ListId}')";
strImagePath=ctx.imagesPath+"oisweb.gif";
menuOption = CAMOpt(rootMenu,strDisplayText,strAction,strImagePath);
menuOption.id = "ID_MySubMenu";
strDisplayText = "并列汇总表";
strAction = "STSNavigate('~site/_layouts/ItemAudit.aspx?ItemId={ItemId}&ListId={ListId}')";
strImagePath=ctx.imagesPath+"oisweb.gif";
menuOption = CAMOpt(rootMenu,strDisplayText,strAction,strImagePath);
menuOption.id = "ID_MySubMenu";
return false;
}
</script>
点击保存--应用--确定--退出编辑模式
好,看到我们期待已久的最终结果,
注意,这里是List和Doc是2个分别的JS方法名。
这个菜单是用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内容:
<Elementsxmlns="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 -->
<CustomActionId="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>
<CustomActionId="ECBItemToolbar"
RegistrationType="List"
RegistrationId="101"
Type="ECBItem"
Location="BugWorkaround:LocationShouldEqualEditControlBlock"
Sequence="106"
Title="Litware ECB item Command">
<UrlActionUrl="/_layouts/litwarefeaturelab.aspx?command=SiteSettingCommand"/>
</CustomAction>
</Elements>
其中第一个CustomAction在Site 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 Sharedweb server extensions12BINstsadm.exe
set TargetUrl=http://huijianming
set FeaturePath=menuFeature.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 Sharedweb server extensions12BINstsadm.exe
set TargetUrl=http://huijianming
set FeaturePath=menuFeature.xml
echo InstallFeature %FeaturePath%
"%SPAdminTool%" -o UnInstallFeature-filename %FeaturePath% -force
echo iisreset
iisreset
将以上的两个XML放到Menu的文件夹中,然后将文件夹拷贝到C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURES
运行部署批处理文件
效果图如下:
文档库新建菜单
文档库操作菜单
网站操作菜单
运行卸载批处理文件