Copy files into sharepoint

I would like to automate the copying of report files (.xsl) into sharepoint. Does someone have a script that will do this (preferably windows cmd or powershell).

Thanks

Ron

September 11th, 2015 6:07pm

Here's a PowerShell script to upload files:

# Set a few variables
$file = "C:\test\myTestFile.txt"
$webUrl = "http://server/sites/yoursite"
$library = "Team Documents"
$overWriteExisting = $True #or add new version if versioning enabled

# do a little SharePoint setup
$web = Get-SPWeb $webUrl
$files = $web.GetFolder($library).Files
$fileNameForLibrary = $file.Substring($file.LastIndexOf("\")+1) 

# read the file
$data = Get-ChildItem $file

# add any needed metadata
$metadata = @{ "Project ID" = "A-200"; "Region" = "North" }

# or if no metadata needed: $metadata = @{}

# do the upload (the following is one line)
$newfile = $files.Add($library + "/" + $fileNameForLibrary, $data.OpenRead(), $metadata, $overWriteExisting)

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 8:58pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics