Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm using SharePoint Foundation 2010.

I have to make a PowerShell script that copies a structure found on a network share. Its all good except for one thing... I know how to make Document Library's and folders inside them, I also know how to upload files to the document library's BUT I can't find out how to upload a file to a folder inside a document library.

For clarification:
Document library
-Folder
-Folder -->Upload to this folder
-Folder

share|improve this question

1 Answer 1

up vote 2 down vote accepted

To create a Document library:

New-SPList -Web http://spwebaddress -ListTitle “Enter Title Here” -ListUrl “ListURL” -Description “Description” -Template “Document Library”

To upload to a folder within document library you should get the spfolder then add to it...

$folder=$web.GetFolder(“FolderName″)
$folder.Files.Add($folder.Url + “/” + $file.Name, [System.IO.Stream]$fileStream, $true)

References:

http://sharepointgroup.wordpress.com/2012/08/17/how-to-upload-a-file-to-sharepoint-document-library-with-powershell/

share|improve this answer
    
That's exactly what I needed, thanks! –  Joren Maurissen Apr 30 '13 at 14:28

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.