Ramblings

December 12, 2006

SharePoint/Powershell Quickie: Upload a directory of files in 4 lines

Filed under: dev — michaelangela @ 7:18 am

Hmm… need to start a Powershell category now!

SharePoint/Powershell Quickie: Upload a directory of files in 4 lines:

Heres 4 lines of code to upload a whole directory of files, in this case pictures, to a SharePoint document or image library. The directory pictures contains the images. The destination is the image library SiteCollectionImages for the portal running on port 2828 $wc = new-object System.Net.WebClient $wc.Credentials = [System.Net.CredentialCache]::DefaultCredentials function getdestname($filename){ “http://sps:2828/sitecollectionimages/” + $(split-path -leaf $filename)} dir “pictures” | % { $uploadname=getdestname $_; $wc.UploadFile($uploadname,”PUT”, $_.FullName) } Have I mentioned PowerShell just rocks?

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: