悠闲小风专栏

SharePoint & Workflow 解决方案

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

第一步:创建Feature

1、用VS2010 新建一个sharepoint 2010 的Empty Sharepoint Project 项目,名称为CustomRibbon。

2、在Features 目录上,添加一个Feature,名称为CustomRibbonButton。

3、定义Feature文件。打开CustomRibbonButton.template.xml文件,进行编辑并保存,代码如下:

 

 <?xml version="1.0" encoding="utf-8" ?>
 
<Feature Id="A8DA4BE9-8F82-4E94-9723-D51E8B5D683E"
  Title
="CustomRibbonButton"
  Description
="CustomRibbonButton"
  Version
="1.0.0.0"
  Scope
="Web"
  xmlns
="http://schemas.microsoft.com/sharepoint/">
  
<ElementManifests>
    
<ElementManifest Location="CustomRibbonElement\Elements.xml" />
  
</ElementManifests>
 
</Feature>

 

第二步:创建支持文件

1、在CustomRibbon项目上,添加新项,选择Empty Elements类项,名称为CustomRibbonElement。

2、定义支持文件。打开Elements.xml文件,进行编辑,代码如下:

代码
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 
 
<CustomAction
   
    
Id="CustomRibbonButton"
    RegistrationId
="101"
    RegistrationType
="List"
    Location
="CommandUI.Ribbon"
    Sequence
="5"
    Title
="Move Documents">
    
<CommandUIExtension>
      
<CommandUIDefinitions>
        
<CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
          
<Button
              
Id="Ribbon.Documents.New.TestButton"
              Alt
="Move Documents"
              Sequence
="5"
              Command
="Test_Button"
              Image32by32
="/_layouts/images/CustomRibbon/network32.GIF"
              Image16by16
="/_layouts/images/CustomRibbon/network16.GIF"              
              LabelText
="Move Documents"
              TemplateAlias
="o1" />
        
</CommandUIDefinition>
      
</CommandUIDefinitions>
      
<CommandUIHandlers>
        
<CommandUIHandler
          
Command="Test_Button"
          CommandAction
="javascript:alert('Welcome To SharePoint 2010 !');" />
      
</CommandUIHandlers>
 
    
</CommandUIExtension>
  
</CustomAction>
 
</Elements>

 

备注说明:
  "CustomAction“部分:
  “Sequence” 属性,这个属性指定了我们要添加的按钮所在组中的位置。
   “Location” 属性,这里指定了这个按钮应该被添加到哪个Tab下的哪个组中,其格式为:Ribbon.[Tab].[Group].Controls._children


  "Command” 属性,这个属性将“CommandUIDefinition” 与“CommandUIHandler” 关联起来。
  “TemplateAlias” 属性,定义了这个按钮在页面中是32X32还是16X16,“o1”是32,“o2”是16。

  “CommandUIHandler” 部分:

  “Command” 属性与第19行的“Command” 相对应,以将Button与其操作关联起来。
  “CommandAction” 标记,在这个标记中我们将定义按钮被按下时将要执行的Javascript脚本。SharePoint 2010为我    们提供了丰富的Javascript API,通过这些API我们可以做更多的事情。

第三步:部署

1、选择CustomRibbon项目,查看属性,在SiteUrl属性上,填写部署的站点,如:http://moss

2、选择CustomRibbon项目,右键“部署”将进行自动部署

 

第四步:查看效果

1、打开一个文档库,选择一个条目,在文件这个标签上,就可以看到刚刚部署的这个ribbon 按钮了。

 

注:用VS2010进行sharepoint 2010的开发还是挺方便的,能够很好的跟sharepoint集成,方便开发,部署与调试。

 

 

 


posted on 2010-07-26 13:25  陈典洪  阅读(1518)  评论(0编辑  收藏  举报