Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is there a way to add the "Link to Document" content type to all existing document libraries in a site/site collection other than editing each one manually? I'm fine to do it with PowerShell if there is a way.

Also is there a way to change the template for the default document library so that all new document libraries will have this functionality?

share|improve this question
add comment

1 Answer

This is untested, but I'd probably do something like this:

$site = get-spsite http://your/site

$rootWeb = $site.RootWeb

$linkToDocCType = $rootWeb.AvailableContentTypes["Link to a Document"]

foreach ($web in $site.AllWebs)
{
    foreach ($list in $web.Lists)
    {
        if ($list.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary)
        {
            $listMatchCTypeId = $list.ContentTypes.BestMatch($linkToDocCType.Id)

            if (!$listMatchCTypeId.IsChildOf($linkToDocCType.Id))
            {
                $webCTypeCopy = $list.ParentWeb.AvailableContentTypes[$linkToDocCType.Id]
                $listCTypeCopy = new-object Microsoft.SharePoint.SPContentType($webCTypeCopy, $list.ContentTypes, $webCTypeCopy.Name)
                $list.ContentTypes.Add($listCTypeCopy)
                $list.Update()
            }
        }
    }

    $web.Dispose()
}

$rootWeb.Dispose()
$site.Dispose()

As far as your second question, about changing the default document library template to always include "Link to a Document", I really don't know. It may be possible, but then again it's my understanding that it's a best-practice to leave the OOB stuff alone and not customize it, as an update from Microsoft might overwrite your customization.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.