Take the 2-minute tour ×
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 = "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 

}
share|improve this question
    
asadewa.wordpress.com/2007/11/19/… 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. blogs.msdn.com/b/cliffgreen/archive/2008/06/23/… –  Ken smith Jun 29 '12 at 16:37
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.