2013-03-25 124 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文件也一起在某个时候...

相关问题