There are multiple methods to achieve this but since today it’s Friday and I’d like to watch Cloverfield’s making of before midnight :), here are two quick’n simple methods:
Method 1: Using WebDav and NET USE
Conditions: this method will work only if SharePoint is running on port 80, does not use form-based authentication and if the WebClient service is running on your client PC (or server, on which it is set to manual startup mode!)
Start PowerShell and enter the command
net use Z: “http://WSSSERVER/Site01/DocLibName/"
Then simply use the copy command:
copy c:demofile.txt Z:
Say what? Use PowerShell for that? It couldn't it work with a standard Windows command-prompt? Yes it can 🙂
Method 2: Using a standard HTTP “PUT”
Conditions: SharePoint should be configured to use form-based authentication, although the code could be adapted to support it.
Let’s use a function to tidy up the code…
$WebMethod = "PUT"
$UploadFullPath = $spDocLibPath + $(split-path -leaf $LocalPath)
$WebClient = new-object System.Net.WebClient
$WebClient.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$WebClient.UploadFile($UploadFullPath, $WebMethod, $LocalPath)
UploadToSPDocLib "c:demofile.txt" "http://WSSSERVER/Site01/DocLibName/"
While I still have other interesting ways to upload files to SharePoint, it will be the subject of another post…