在SharePoint中动态添加修改Custom Action
来源:互联网 发布:淘宝冬季女装 编辑:程序博客网 时间:2024/05/22 05:15
在SharePoint中,常用的添加一个custom action的方法是使用配置文件,例如下面的配置文件向SharePoint中添加了一个custom action:
<CustomAction Id="SharePoint.TestLab.CustomAction" GroupId="PersonalActions" Location="Microsoft.SharePoint.StandardMenu" Sequence="1000" Description="SharePoint.TestLab.CustomAction Description" Title="SharePoint.TestLab.CustomAction Title" <UrlAction Url="~site/_layouts/SharePoint.TestLab.CustomAction/CustomAction.aspx"/> </CustomAction>
从配置信息中可以知道,这个custom action是在切换用户的下拉菜单中添加了一个link,指向一个页面。
这样的custom action一旦部署就不能动态的修改了,例如修改title和description,以及URL,location等都需要改配置文件,重启IIS才能生效。
如果想根据用户的设置来动态的添加和修改custom action,需要使用代码来完成。
SharePoint提供了“SPUserCustomAction”这个对象(仅支持SharePoint 2010和2013),以及在SPSite和SPWeb对象上的“UserCustomActions”属性来完成这个功能,以下是部分示例代码:
向Web中(也可以在Site中,使用SPSite.UserCustomActions属性,这取决于custom action的使用范围)添加一个custom action:
SPUserCustomAction action = Web.UserCustomActions.Add(); action.Title = "SharePoint.TestLab.CustomAction Title"; action.Description = "SharePoint.TestLab.CustomAction Description"; action.Group = "PersonalActions"; action.Location = "Microsoft.SharePoint.StandardMenu"; action.Sequence = 1000; action.Url = "~site/_layouts/SharePoint.TestLab.CustomAction/CustomActionSiteSetting.aspx"; action.Name = "SharePoint.TestLab.CustomAction"; action.Update();从UserCustomActions集合中获取一个custom action:
var action = Web.UserCustomActions.FirstOrDefault( item => item.Name == "SharePoint.TestLab.CustomAction");
我试着使用action.Delete()方法来删除一个action,然后update action,update web,但是失败了,似乎这个删除操作是有问题的,具体的原因还不清楚,这个delete方法本质上是调用了一个存储过程(proc_DeleteCustomAction),从数据库中删除一个custom action。
如果不能删除,可以改变action的location属性,来隐藏它,也可以达到一样的目的:
action.Location = "Removed"; action.Update();
0 0
- 在SharePoint中动态添加修改Custom Action
- 在VS2012里创建SharePoint Ribbon Custom Action
- 如何在SharePoint中创建Custom Master Page
- Sharepoint习题——Custom Action
- 修改SharePoint列表中“添加新项目”链接
- Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010[Sharepoint中添加自定义菜单]
- 如何在Windows Installer的Custom Action中Sleep
- 在SharePoint中添加PDF图标显示
- html的form中动态添加action
- Take Custom Action Upon SharePoint FBA User Login
- Custom Ribbon Action (DownLoad Multiple File) -------------SharePoint 2010
- SharePoint 2010 Download as Zip File Custom Ribbon Action
- 在sharepoint中找不到在AD中添加的组
- 给SharePoint页面添加自定义页脚Custom footer
- 我的图片AI中 Custom Action
- 使用Quickpart/Smartpart在Sharepoint中添加Ajax问题
- 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler)
- 如何使用SharePoint Designer 在Ribbon中添加自定义操作
- chromium
- ViewGroup里定义的三个常量
- Microsoft Visual Studio快捷键
- 我的扫描二维码终结了整整一天的 黑白转彩色
- Hadoop 、Hbase、zookeeper 集群环境搭建
- 在SharePoint中动态添加修改Custom Action
- LeetCode之Linked List Cycle II
- 编译tcprstat
- win7硬盘安装ubuntu
- java冒泡排序
- WIN32_FIND_DATA结构
- Android开源测试框架学习
- FORM级别和数据库级别的Trace
- 堵塞Web漏洞