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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.