SPFileCollection Class – copy files to another document library

Original Post: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfilecollection.aspx

**Please note** I didn’t attempt to “dispose”, so make sure to add it…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$PSSnapin = Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
clear
 
$org = "http://blueleader"
$dest = "http://redleader"
 
$orgLibrary = (Get-SPWeb $org).Folders["Documents"]
$destLibrary = (Get-SPWeb $dest).Folders["Documents"]
$destFiles = $destLibrary.Files
foreach ($file in $orgLibrary.Files)
{
	$curFile = $file.OpenBinary()
	$destURL = $destFiles.Folder.Url + "/" + $file.Name
	$destFiles.Add($destURL, $curFile, $true)
}

 

4 Comments

  1. anubhav says

    Thanks for the above code but can not adding sub foldfers items. Kindly help.

    Reply
  2. Darrell says

    Great Site. Thanks for the script. Do you know of a way to get the meta data associated with the documents via PowerShell. I know how to do it using C# and the SP object model, but haven’t had enough experience with te PowerShell side of things.

    Thanks,
    Darrell

    Reply
  3. Snigdha says

    This document is really help full and help me think in a different ways .I have a query like :is it feasible to make a power shell script for moving a lot of files from share point site in to one folder present inside a server .Please reply ….

    Reply

Leave a Reply

Leave a Reply
  • (required)
  • (required) (will not be published)

  • Tags

  • Subscribe
  • Pages

  • More

  • Disclaimer…

    This is my personal weblog. The opinions expressed herein are my own and are not representative of any 3rd party influence. The owner of this blog reserves the right to edit or delete any comments submitted to this blog without notice if they are deemed to be spam, offensive or otherwise inappropriate. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.


    Lastly, I do my best to document my sources if the article is not of my own creation. If I have missed or forgotten to source your work. I would love feedback via the comments section. Thank you.