Monday, February 3, 2014

Upload Files to SharePoint Remotely using Web Client and PowerShell

If you want to upload file to SharePoint document library from client side (or remotely), Here is the nifty PowerShell code snippet.

Upload file to SharePoint - Web Client HTTP put method:

#Variable for Source folder in Local machine
$FilesLocation ="D:\Scripts\Reports\"

#Create new web client object
$WebClient = new-object System.Net.WebClient
$WebClient.Credentials = [System.Net.CredentialCache]::DefaultCredentials

#Use these lines if you use different credentials
#$cred = new-object System.Net.NetworkCredential("USER NAME","PASSWORD","DOMAIN")
#$WebClient.credentials = $cred

#Target File Location to upload
function Set-DestinationFile($FileName)
   $TargetLocation + $(split-path -leaf $FileName)

  #Iterate throgh each file and upload
  Get-ChildItem $FilesLocation | ForEach-Object {

  $DestinationFile= Set-DestinationFile $_;

  #upload file to sharepoint using webclient
  $WebClient.UploadFile($DestinationFile,"PUT", $_.FullName)

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...