jeudi 29 janvier 2015

Creating files in Document library in SharePoint 2010 using Powershell



I am using below script to copy files from one library to another:



$SourceWebURL = "http://sitecollection/sites/site"
$SourceLibraryTitle = "doclib"
$DestinationWebURL = "http://sitecollection/sites/site"
$DestinationLibraryTitle = "doclib"
$ssite = Get-SPSite $SourceWebURL
$sweb = $ssite.OpenWeb("subsite")
$dsite = Get-SPSite $DestinationWebURL
$dweb = $dsite.OpenWeb("Archivesubsite")
$sList = $sWeb.Lists | ? {$_.Title -eq $SourceLibraryTitle}
$dList = $dWeb.Lists | ? {$_.title -like $DestinationLibraryTitle}
$AllFolders = $sList.Folders
$RootFolder = $sList.RootFolder
$RootItems = $RootFolder.files

foreach($Folder in $AllFolders)
{
echo $Folder.url
foreach($Item in $Folder)
{
$sBytes = $RootItem.OpenBinary()
$dFile = $dList.RootFolder.Files.Add($Item.Name, $sBytes, $true)
$dFile.Update()
}
}


I want to loop in each folder in doclib and create the files in folders in destination library. Error I am getting is : You cannot called a method on null valued expression.








0 commentaires:

Enregistrer un commentaire