SharePoint自动化系列——Add content type to list.

简介: 转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish content type,并在Monitor中跑和Content type同步相关的job,这里我写...

转载请注明出自天外归云的博客园: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已经成功加入:

相关文章
java.lang.Error: Unresolved compilation problem: The type List is not generic; it cannot be parame
java.lang.Error: Unresolved compilation problem: The type List is not generic; it cannot be parame
|
4月前
|
JavaScript
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
85 0
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
192 0
Could not resolve element type of Iterable type xxxxx.RequestParam java.util.List<?>. Not declared?
Could not resolve element type of Iterable type xxxxx.RequestParam java.util.List<?>. Not declared?
Could not resolve element type of Iterable type xxxxx.RequestParam java.util.List<?>. Not declared?
|
Linux 开发工具 开发者
有关Linux系统出现Malformed line 1 in source list /etc/apt/sources.list (type)问题的解决方式
以下内容仅代表个人意见,本人亲测有效,如果没有效果可以现将之前的sources.list备份的文件恢复 重要的事情说三遍:记得备份,记得备份,记得备份 本文中所阐述的问题大致是因为由于不正常的关闭影响的sources.list文件的异常,以导致这种问题生成的原因,因此在这里考虑进行重新创建sources.list文件来解决问题的处理方式 本蒟蒻在昨晚做Linux(我用的是Debian,教学要求 )的时候,因为要在 /etc/apt/sources.list里添加一些东西,但是更改完之后,发生了错误:
601 0
有关Linux系统出现Malformed line 1 in source list /etc/apt/sources.list (type)问题的解决方式
SAP QM 执行事务代码QP01,系统报错 -Material type FOOD is not defined for task list type Q-
SAP QM 执行事务代码QP01,系统报错 -Material type FOOD is not defined for task list type Q-
SAP QM 执行事务代码QP01,系统报错 -Material type FOOD is not defined for task list type Q-
成功解决TypeError: unsupported operand type(s) for +: 'dict_items' and 'list'
成功解决TypeError: unsupported operand type(s) for +: 'dict_items' and 'list'
List使用时不支持add insert 等方法处理详情
List使用时不支持add insert 等方法处理详情
387 0

热门文章

最新文章