SharePoint 2010 – How to add files in a folder to a SharePoint library with PowerShell
14 March 2012 // 1 CommentHow to add files in a folder to a SharePoint library with PowerShell?
Use this script!
$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
}
Similar posts
-
SharePoint 2010 - How to hide/remove the recycle bin and view all ...
10 April 2012 // 2 CommentsHow to hide/remove the recycle bin and view all site contents in SharePoint 2010?
-
SharePoint 2010 - Change 'Specify your own value' in a survey
3 April 2012 // 5 CommentsTo change 'Specify your own value' in a survey, just put this code in the NewForm.aspx and EditForm....
-
SharePoint 2010 - Add redirect in survey to manual page after fin ...
2 April 2012 // 11 CommentsToday I wrote a code for a customer that wanted to redirect to a different page after the users clic...
-
SharePiont 2010 - How to backup and restore a SharePoint list wit ...
19 March 2012 // 0 CommentsBackup a SharePoint list with PowerShell: Restore a SharePoint list with PowerShell:
I have a similar requirement which needs the user profile photo to be upladed programmatically and i am following the below link.
(http://get-spscripts.com/2010/12/upload-multiple-user-profile.html?showComment=1343631879879#c2583649327795206294)
But I am getting an error at this step
$spFile = $spPhotosFolder.Files.Add($spFullPath, $_.OpenRead(), $true)
It is throwing the following error
Copying domain_abdul.JPG to User Photos in …
The script has stopped because there has been an error: Exception calling “Add” with “3″ argument(s): “The system cannot find the file specified.
(Exception from HRESULT: 0×80070002)”
Your help will be greatful as i am stuck with this requirement
Thanks