2013-03-25 2 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 파일을 속이는 끝낼 수 있습니다 불필요한 세부 사항은 여기 만의 요점은 구문 분석 할만큼 쉽다

관련 문제