hwo to move nested folder as it is to sharepoint document lib
-
Thursday, December 06, 2012 7:03 AM
Hi All,
I putting up a script together to move nested folders with files in it to a doc lib n sharepoint as it is
I'm sure i should be able to use powershell for this and i need an assistance ... almost there.This snipped does work but i get error:
Method invocation failed because [System.IO.DirectoryInfo] doesn't contain a method named 'OpenRead'.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null [System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") [System.Reflection.Assembly]::LoadWithPartialName("System.web") function UploadAllFiles($WebURL, $DocLibName, $FolderPath) { #Get the Web & Lists to upload the file $site = New-Object Microsoft.SharePoint.SPSite($WebURL) $web= $site.OpenWeb() #Get the Target Document Library to upload $List = $Web.GetFolder($DocLibName) #Get the Files from Local Folder $Files = Get-ChildItem $FolderPath #You can filter files by: -filter “*.pdf” #upload the files foreach ($File in $Files) { #Get the Contents of the file to FileStream #Error here Method invocation failed because [System.IO.DirectoryInfo] doesn't contain a method named 'OpenRead'. $stream = (Get-Item $file.FullName).OpenRead() $uploaded = $List.Files.Add($File.Name,$stream) $stream.Dispose() } #Dispose the site object $site.Dispose() } #call the upload function UploadAllFiles "http://ServerName/" "TestDoc" "D:\myrootfolder"This works but it doesn't copy the nested folder across as it is it just copies only the files inside the root folder.
Any help will be appreciated.
Thanks a lot
All Replies
-
Monday, December 31, 2012 5:48 PMModerator
That's correct; indeed, a DirectoryInfo object does not have an OpenRead method.
What would it mean, anyway? A directory doesn't have content like a file does; it contains other files and directories.
Bill
- Proposed As Answer by Bill_StewartMicrosoft Community Contributor, Moderator Friday, January 11, 2013 10:51 PM
- Marked As Answer by IamMredMicrosoft Employee, Owner Monday, January 21, 2013 7:23 AM

