2013-03-25 122 views
1

我試圖使用PowerShell 2.0創建到SharePoint 2010中文檔的鏈接。我已經啓用了其他內容類型,並將「鏈接到文檔」內容類型添加到相關文檔庫中。使用PowerShell在SharePoint共享文檔列表中創建'鏈接到文檔'

我試圖鏈接到的文檔位於同一網站集中另一個網站上的另一個共享文檔列表中。實際文件嵌套在名爲「PM」的子文件夾中。文件類型可以從excel文件到word文件到PDF文件。

我已經手動測試過程(共享文檔 - >新建文檔 - >鏈接到文檔 - > ...),它工作正常(如右下角的箭頭所指示的文檔圖標當我完成時),但我似乎無法讓它與PowerShell一起工作。有任何想法嗎?

這是唯一的非PowerShell的解決方案,我來翻過至今: http://howtosharepoint.blogspot.com/2010/05/programmatically-add-link-to-document.html

回答

0

我得到了它的移植上述方案中最後的工作。有多餘的細節,但是它的精神是很容易分析出:

# 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文件也一起在某個時候...

相關問題