Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi Friends,

I have a few files on a network location which i to need overwrite to a SharePoint Document Library, this should happen daily on a specific time.

I am new to SharePoint, so please provide me the details steps if possible.

Thanks in Advance
Posted
Updated 19-Apr-14 22:41pm
v3

1 solution

You can use a PowerShell script and schedule it using Windows Scheduler to run at a specific time every day.

People would argue to use SP Timer Jobs, but having the good old Scheduled jobs makes it cloud ready considering Microsoft shift to Office 365 where you can not run a Full Trust solution.

This script should help:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
     Add-PSSnapin Microsoft.SharePoint.PowerShell;
 }

#Site Collection where you want to upload files
$siteCollUrl = "http://SPWebApplication/sites/Upload" 
#Document Library where you want to upload files
$libraryName = "Shared Documents"
#Physical/Network location of files
$reportFilesLocation  = "C:\Users\manas\Desktop\File"

$spSourceWeb = Get-SPWeb $siteCollUrl;
$spSourceList = $spSourceWeb.Lists[$libraryName];
   
if($spSourceList -eq $null)
{
	Write-Host "The Library $libraryName could not be found."
	return;
}

$files = ([System.IO.DirectoryInfo] (Get-Item $reportFilesLocation)).GetFiles()
foreach($file in $files)
{ 
	#Open file
	$fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()
 
	#Add file
	$folder =  $spSourceWeb.getfolder($libraryName)
 
	Write-Host "Copying file $file to $libraryName..."
	$spFile = $folder.Files.Add($folder.Url + "/" + $file.Name, [System.IO.Stream]$fileStream, $true)
		 
	#Close file stream
	$fileStream.Close();
					   
}
$spSourceWeb.dispose();
Write-Host "Files have been uploaded to $libraryName." 


[EDIT]: I just blogged about this question with more details. See here:

http://manasbhardwaj.net/upload-files-library-sharepoint-2013-using-powershell/[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900