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


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

  • 相关阅读:
    angular入门--绑定字符串
    mongodb安装与mongo vue的使用
    css3-pointer-events_demo
    面向对象的六大原则
    AutoMapper简明教程(学习笔记)
    jquery cookie的用法
    MVC 异常处理机制
    查询最近修改的脚本
    运行page页面时的事件执行顺序
    游标简单的使用
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/5105158.html
Copyright © 2020-2023  润新知