1

Okay, I am using following powershell script to add files to document library. Initially, the library only had built in content type "Documents". But now its another content type "Link to a Document". What's the method or code to add an item in the document library without a file for "link to a document type" content type?

$siteurl = "http://sharepoint.com"
$spWeb = Get-SPWeb $siteurl
$docLibraryName = "LibraryName"
$localFolderPath = "D:\Upload"
$docLibrary = $spWeb.Lists[$docLibraryName] 

$files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles() | ForEach-Object {
    $fileStream = ([System.IO.FileInfo] (Get-Item $_.FullName)).OpenRead()
    $contents = new-object byte[] $fileStream.Length
    $fileStream.Read($contents, 0, [int]$fileStream.Length);
    $fileStream.Close();
    write-host "Copying" $_.Name "to" $docLibrary.Title "in" $spWeb.Title "..."
    $folder = $docLibrary.RootFolder
    $spFile = $folder.Files.Add($folder.Url + "/" + $_.Name, $contents, $true)
    $spItem = $spFile.Item 

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.