转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/

将创建好的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的名字。调用方法如下:

运行结果如下:

之后在SharePoint中相应list的list setting页面我们可以看到,content type已经成功加入:

SharePoint自动化系列——Add content type to list.的更多相关文章

  1. SharePoint自动化系列——Add/Remove "Record" from items

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 目的:批量的将SharePoint items变成records或者将records变成普通的it ...

  2. SharePoint自动化系列——Add/Remove “Hold” from items

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 问题1: 1.如果SharePoint item被添加了hold,通过UI界面来对SharePoi ...

  3. SharePoint自动化系列——Content Type相关timer jobs一键执行

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...

  4. SharePoint自动化系列——Error features自动deactivate

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ SharePoint Content Deployment prerequisite——Error ...

  5. SharePoint自动化系列——Site/Web/List级别的导航菜单

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 需求:在不同的测试用例中,对脚本中不确定的因素需要和用户交互来确定,比如选择哪个site,选择哪个 ...

  6. SharePoint自动化系列——Create a local user and add to SharePoint

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 实现过程:在本地创建一个local user并将该user添加到Administrators组中, ...

  7. SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow

    Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Des ...

  8. SharePoint自动化系列——创建MMS terms

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...

  9. SharePoint自动化系列——通过PowerShell创建SharePoint Lists

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

随机推荐

  1. 查看linux [Fedora] 系统信息

    系统版本: $ /etc/issue Fedora release (Heisenbug)或者$ cat /etc/issue 系统位数: $ getconf LONG_BIT64 内核信息: $ c ...

  2. [原创]java WEB学习笔记86:Hibernate学习之路-- -映射 n-n 关系,单向n-n,双向n-n

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  3. 对ImageView.ScaleType的详解

    设置的方式有两种: 1.在layout.xml里面定义android:scaleType = "center" 2.在代码中调用imageview.setScaleType(Ima ...

  4. 怎么在eclipse里调试WebDriver的源代码(转)

    当你看完WebDriver的工作原理这篇博客以后,是不是也跃跃欲试想印证文章里的理论是不是正确,想自己也看下webdriver的源代码,并且调试下,通过代码来更深入的了解WebDriver的工作原理. ...

  5. android中在代码中设置margin属性

    1,不多说,小知识点,直接上代码 LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(15, 15);// 创 ...

  6. 在C#中使用LOG4NET(winform程序

    http://www.csharpwin.com/csharpspace/678.shtml 1.下载log4net (Google log4net) 2.unzip log4net 3.运行VS,新 ...

  7. mongo自带测试

    benchrun > res = benchRun({ ops:[{ ns:"test.foo", op:"insert", doc:{y:{,]}} } ...

  8. 夺命雷公狗—angularjs—14—$location的作用

    废话不多说看下,我们直接来走代码看下效果如何 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  9. struts2 18拦截器详解(七)

    ChainingInterceptor 该拦截器处于defaultStack第六的位置,其主要功能是复制值栈(ValueStack)中的所有对象的所有属性到当前正在执行的Action中,如果说Valu ...

  10. 操作系统双语阅读 - Schedulers调度器2

    Most processes can be described as either I/O bound or CPU bound. 大多数进程都可以描述为IO绑定或者CPU绑定. An I/O-bou ...