Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 = ""
$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);
    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 

share|improve this question… Here is a good link on determining Content Type. – Ken smith Jun 29 '12 at 16:21
shows how to a link to item in doc lib.… – Ken smith Jun 29 '12 at 16:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.