Answered by:
Recursively find all files which are recently modified in the folder and download

Question
-
Hi.
I have a document library in which I have multiple files. I want to identify all the files which are modified recently ( or in the last 24 hours ) and download it to the system.
How to achieve this using jQuery / Javascript model ?
Thanks
Wednesday, November 6, 2019 3:24 PM
Answers
-
Hi,
If you want to download files which are modified recently, I suggest you use PowerShell to achieve it.
PowerShell with Server Side Object Model:
$Destination = "C:\temp\DL" $Web = Get-SPWeb "http://sp2013/sites/team" $DocLib = $Web.Lists["DL"] $spQuery = New-Object Microsoft.SharePoint.SPQuery $spQuery.ViewAttributes = "Scope='Recursive'" $camlQuery ="<Where><Gt><FieldRef Name ='Modified' IncludeTimeValue='TRUE'/><Value Type ='DateTime'><Today OffsetDays='-1'/></Value></Gt></Where>" $spQuery.Query = $camlQuery $DocLibItems = $DocLib.GetItems($spQuery) foreach ($DocLibItem in $DocLibItems) { $File = $Web.GetFile($DocLibItem.Url) $Binary = $File.OpenBinary() $Stream = New-Object System.IO.FileStream($Destination + "\" + $File.Name), Create $Writer = New-Object System.IO.BinaryWriter($Stream) $Writer.write($Binary) $Writer.Close() }
PowerShell with Client Side Object Model:
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" $Destination = "C:\temp\DL" $siteURL = "http://sp2013/sites/team" $username="administrator" $password="xx" $domain="console" $listName="DL" $creds = New-Object System.Net.NetworkCredential($username, $password, $domain); $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL) $ctx.credentials = $creds try{ $DocLib = $ctx.web.Lists.GetByTitle($listName) #Define the CAML Query $Query = New-Object Microsoft.SharePoint.Client.CamlQuery $Query.ViewXml = "@ <View Scope='Recursive'> <Query> <Where> <Gt><FieldRef Name ='Modified' IncludeTimeValue='TRUE'/><Value Type ='DateTime'><Today OffsetDays='-1'/></Value></Gt> </Where> </Query> </View>" $listItems = $DocLib.GetItems($Query) $ctx.load($listItems) $ctx.executeQuery() foreach($DocLibItem in $listItems){ $FileInfo = [Microsoft.SharePoint.Client.File]::OpenBinaryDirect($ctx,$DocLibItem["FileRef"]) $WriteStream = [System.IO.File]::Open($Destination+ "\" + $DocLibItem["FileLeafRef"],[System.IO.FileMode]::Create) $FileInfo.Stream.CopyTo($WriteStream) $WriteStream.Close() } } catch{ write-host "$($_.Exception.Message)" -foregroundcolor red }
If you still want to use JavaScript code, please check the thread below.
Download multiple files from sharepoint library using JSOM/ECMAScript
Best Regards,
Dennis
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
SharePoint Server 2019 has been released, you can click here to download it.
Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.- Proposed as answer by Lee__liMicrosoft contingent staff Tuesday, November 12, 2019 6:16 AM
- Marked as answer by Venkatzeus Friday, December 27, 2019 9:24 AM
Thursday, November 7, 2019 3:21 AM
All replies
-
Hi,
If you want to download files which are modified recently, I suggest you use PowerShell to achieve it.
PowerShell with Server Side Object Model:
$Destination = "C:\temp\DL" $Web = Get-SPWeb "http://sp2013/sites/team" $DocLib = $Web.Lists["DL"] $spQuery = New-Object Microsoft.SharePoint.SPQuery $spQuery.ViewAttributes = "Scope='Recursive'" $camlQuery ="<Where><Gt><FieldRef Name ='Modified' IncludeTimeValue='TRUE'/><Value Type ='DateTime'><Today OffsetDays='-1'/></Value></Gt></Where>" $spQuery.Query = $camlQuery $DocLibItems = $DocLib.GetItems($spQuery) foreach ($DocLibItem in $DocLibItems) { $File = $Web.GetFile($DocLibItem.Url) $Binary = $File.OpenBinary() $Stream = New-Object System.IO.FileStream($Destination + "\" + $File.Name), Create $Writer = New-Object System.IO.BinaryWriter($Stream) $Writer.write($Binary) $Writer.Close() }
PowerShell with Client Side Object Model:
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" $Destination = "C:\temp\DL" $siteURL = "http://sp2013/sites/team" $username="administrator" $password="xx" $domain="console" $listName="DL" $creds = New-Object System.Net.NetworkCredential($username, $password, $domain); $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL) $ctx.credentials = $creds try{ $DocLib = $ctx.web.Lists.GetByTitle($listName) #Define the CAML Query $Query = New-Object Microsoft.SharePoint.Client.CamlQuery $Query.ViewXml = "@ <View Scope='Recursive'> <Query> <Where> <Gt><FieldRef Name ='Modified' IncludeTimeValue='TRUE'/><Value Type ='DateTime'><Today OffsetDays='-1'/></Value></Gt> </Where> </Query> </View>" $listItems = $DocLib.GetItems($Query) $ctx.load($listItems) $ctx.executeQuery() foreach($DocLibItem in $listItems){ $FileInfo = [Microsoft.SharePoint.Client.File]::OpenBinaryDirect($ctx,$DocLibItem["FileRef"]) $WriteStream = [System.IO.File]::Open($Destination+ "\" + $DocLibItem["FileLeafRef"],[System.IO.FileMode]::Create) $FileInfo.Stream.CopyTo($WriteStream) $WriteStream.Close() } } catch{ write-host "$($_.Exception.Message)" -foregroundcolor red }
If you still want to use JavaScript code, please check the thread below.
Download multiple files from sharepoint library using JSOM/ECMAScript
Best Regards,
Dennis
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
SharePoint Server 2019 has been released, you can click here to download it.
Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.- Proposed as answer by Lee__liMicrosoft contingent staff Tuesday, November 12, 2019 6:16 AM
- Marked as answer by Venkatzeus Friday, December 27, 2019 9:24 AM
Thursday, November 7, 2019 3:21 AM -
Hi,
Would you please provide us with an update on the status of your issue?
Best Regards,
DennisPlease remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
SharePoint Server 2019 has been released, you can click here to download it.
Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.Friday, November 15, 2019 9:17 AM -
Thanks and apologies for the delay in responding.
This is fixed by following the code.
Friday, December 27, 2019 9:25 AM