【问题标题】:Create a 'Link to a Document' in a SharePoint Shared Document List using PowerShell使用 PowerShell 在 SharePoint 共享文档列表中创建“文档链接”
【发布时间】:2013-03-15 13:29:53
【问题描述】:

我正在尝试使用 PowerShell 2.0 在 SharePoint 2010 中创建指向文档的链接。我已经启用了其他内容类型并将“链接到文档”内容类型添加到相关文档库中。

我尝试链接到的文档位于同一网站集中另一个网站上的不同共享文档列表中。实际文件嵌套在名为“PM”的子文件夹中。文件类型可以从 excel 文件到 word 文件再到 PDF。

我已经手动测试了该过程(共享文档 -> 新文档 -> 链接到文档 -> ...)并且工作正常(如右下角带有箭头的文档图标所示)我已经完成了),但我似乎无法让它与 PowerShell 一起使用。有什么想法吗?

这是迄今为止我遇到的唯一非 PowerShell 解决方案: http://howtosharepoint.blogspot.com/2010/05/programmatically-add-link-to-document.html

【问题讨论】:

    标签: sharepoint powershell sharepoint-2010 powershell-2.0


    【解决方案1】:

    通过移植上述解决方案,我终于让它工作了。这里有多余的细节,但它的要点很容易解析出来:

    # Push file links out to weekly role page
    $site = New-Object Microsoft.SharePoint.SPSite($roleURL)
    $web = $site.OpenWeb()
    $listName = "Shared Documents"
    $list = $web.Lists[$listName]
    $fileCollection = $list.RootFolder.files
    ForEach ($doc in $docLoadList) {
        $parsedFileName = $d.Split("\")
        $index = $parsedFileName.Length
        $index = $index - 1
        $actualFileName = $parsedFileName[$index]
        $existingFiles = Get-ExistingFileNames $homeURL
        If ($existingFiles -Match $actualFileName) {
            $existingFileObject = Get-ExistingFileObject $actualFileName $homeURL
            $docLinkURL = Get-ExistingFileURL $actualFileName $homeURL
            # Create new aspx file
            $redirectFileName = $actualFileName
            $redirectFileName += ".aspx"
            $redirectASPX = Get-Content C:\Test\redirect.aspx
            $redirectASPX = $redirectASPX -Replace "#Q#", $docLinkURL
            $utf = new-object System.Text.UTF8Encoding
            $newFile = $fileCollection.Add($redirectFileName, $utf.GetBytes($redirectASPX), $true)
            # Update the newly added file's content type
            $lct = $list.ContentTypes["Link to a Document"]
            $lctID = $lct.ID
            $updateFile = $list.Items | ? {$_.Name -eq $redirectFileName}
            $updateFile["ContentTypeId"] = $lctID
            $updateFile.SystemUpdate()
            $web.Dispose()
        }
    }
    

    我可能最终也会在某个时候将脚本中的 .aspx 文件串在一起......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-22
      • 2018-10-04
      • 2018-12-17
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 2010-12-08
      相关资源
      最近更新 更多