SharePoint自动化系列——Add content type to list.
2016-01-06 12:59
267 查看
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/
将创建好的content type(若是跨web application需要事先publish content type,并在Monitor中跑和Content type同步相关的job,这里我写好了一个脚本,一键执行所有和content type相关的jobs)添加到指定的SharePoint list中,代码如下(以下代码保存到桌面“AddCTToList.ps1”文件中):
按提示先后输入:站点的url,list的title,content type的名字。调用方法如下:
![](http://images2015.cnblogs.com/blog/714263/201601/714263-20160106125738996-757898183.png)
运行结果如下:
![](http://images2015.cnblogs.com/blog/714263/201601/714263-20160106125612903-1942714205.png)
之后在SharePoint中相应list的list setting页面我们可以看到,content type已经成功加入:
将创建好的content type(若是跨web application需要事先publish content type,并在Monitor中跑和Content type同步相关的job,这里我写好了一个脚本,一键执行所有和content type相关的jobs)添加到指定的SharePoint list中,代码如下(以下代码保存到桌面“AddCTToList.ps1”文件中):
Add-PSSnapin Microsoft.SharePoint.PowerShell function AddCTToList() { $webUrl = Read-Host "Enter the web url" $web = Get-SPWeb $webUrl $ListTitle = Read-Host "Enter the list title" $List = $web.Lists[$ListTitle] if ($List -ne $null) { $List.ContentTypesEnabled = $true $List.Update() $CTName = Read-Host "Enter the content type name" $CT = $web.ContentTypes[$CTName] $List.ContentTypes.Add($CT) $List.Update() Write-Host "Content type " $CT.Name " added to list " $ListTitle -ForegroundColor Green } else { Write-Host "The list " $ListTitle " does not exist in site " $web.Title } } AddCTToList
按提示先后输入:站点的url,list的title,content type的名字。调用方法如下:
![](http://images2015.cnblogs.com/blog/714263/201601/714263-20160106125738996-757898183.png)
运行结果如下:
![](http://images2015.cnblogs.com/blog/714263/201601/714263-20160106125612903-1942714205.png)
之后在SharePoint中相应list的list setting页面我们可以看到,content type已经成功加入:
![](http://images2015.cnblogs.com/blog/714263/201601/714263-20160106130949606-1015233279.png)
相关文章推荐
- PlayWithUnion
- iOS 理解使用多线程技术之NSThread
- [PTA] 4-11 Shortest Path [1] (25分)
- 期末成绩
- Web Worker在WebKit中的实现机制
- eclipse弹出框报错
- configure: error: jpeglib.h not found.
- Xcode插件之Alcatraz的安装和遇到的问题
- setjmp的使用 -循环求1~100的和
- Java Script 第六节课 Java Script的算术运算符的例子
- 程序员能力矩阵
- 模型美术规范
- iOS开发:小技巧积累
- frisbee
- java List、Object、String、Map转json 工具类
- How many '1's are there
- 浅谈socket长连接和短连接的区别!
- ExoPlayer编译的重要设置
- 使用BorderLayout和默认布局时的一些注意
- js事件监听器用法实例详解-注册与注销监听封装