本文讲述在SharePoint2013 中使用文档库Scheduling (计划发布功能)的步骤和注意的事项。
文档库Scheduling (计划发布功能)用于设定当文档通过审批后特定的时间区间内才可以被普通用(非管理员,审批人员和作者)户看到。也就是说要启用Scheduling,必须先启用文档库的内容审批和小版本控制。这是官方文档的说法,但是笔者注意到除此之外Draft Item Security要设置成Only users who can approveitems (and the author of the item) 才行:
另外,当在系统文档库上启用Scheduling时,SharePoint会自动加列PublishingExpirationDate(Scheduling End Date) 和 PublishingStartDate (Scheduling Start Date)
但是当重新新建一个文档库时,启用Scheduling时上面两列不会自动添加,可以有两个方法解决
1. 使用系统文档库模板
a. 将系统文档库存为模板,如果看不到另存模板的连接可以直接使用/_layouts/15/savetmpl.aspx?List=ListID可以从文档库设置中找到,或者直接把listedit.aspx换成savetmpl.aspx: /_layouts/15/listedit.aspx?List=%7B465AD054%2DD81B%2D495F%2DAA9F%2D6E44053A3B63%7D
b. 再使用a步得到的文档库模板新建文档库,这样新建出来的文档库启用Scheduling时上面两列就会自动添加了
2. 启用Scheduling后从Site column中添加这两列PublishingExpirationDate(Scheduling End Date)和 PublishingStartDate(Scheduling Start Date)
用PowerShell的话可以这样写:
Param(
[parameter(Mandatory=$true)]
[alias("web")]
$webUrl,
[parameter(Mandatory=$true)]
[alias("DocumentLib")]
$documentLibTitle
)
$webSite = get-SPWeb $webUrl
$documentLib = $webSite.Lists[$documentLibTitle]
Write-host "Enable content approval"
$documentLib.EnableModeration = $true
Write-host "Enable minor version"
$documentLib.EnableMinorVersions = $true
$documentLib.DraftVersionVisibility = 2; # Only users who can approve items (and the author of the item), lib.DraftVersionVisibility = DraftVisibilityType.Approver
$documentLib.Update()
[Microsoft.SharePoint.Publishing.PublishingWeb]::EnableScheduling($documentLib);
# Check if the list have the two column "Scheduling Start Date" and "Scheduling End Date"
## refresh the document library
$documentLib = $webSite.Lists[$documentLibTitle]
$scheduleFields = @{"PublishingStartDate" = "Scheduling Start Date"; "PublishingExpirationDate" = "Scheduling End Date"}
foreach($contentType in $documentLib.ContentTypes)
{
if($contentType.Id.ToString().StartsWith("0x0120"))
{
Write-host "skip the content folder"
continue; // skip the content folder
}
foreach($scheduleField in $scheduleFields.GetEnumerator())
{
Write-host $scheduleField.Value
if(-Not $contentType.Fields.ContainsFieldWithStaticName($scheduleField.Name))
{
$listField = $webSite.Site.RootWeb.Fields[$scheduleField.Value];
$spFiledLink = New-Object Microsoft.SharePoint.SPFieldLink($listField);
Write-host "Add " $scheduleField.Value " for content type" $contentType.Name
$contentType.FieldLinks.Add($spFiledLink);
}
}
$contentType.Update();
$documentLib.Update();
}
$webSite.Dispose();
Write-host "Done!" -foregroundcolor green