Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you really need a script rather than writing code (such as a timer job) then use <a href="http://en.wikipedia.org/wiki/Windows_PowerShell" rel="nofollow noreferrer">Powershell</a> to access the SharePoint .NET objects with a scripting engine. Once you've written the script, set up a Windows scheduled task to run it every day.</p> <p>In the script follow <a href="https://stackoverflow.com/questions/519374/script-to-delete-files-older-than-a-day-in-sharepoint-document-library/520133#520133">Lars' guidance</a> on using one of those two query classes. Then from the query results you can obtain a reference to each SPListItem you'd like to delete. Either use <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.delete.aspx" rel="nofollow noreferrer">SPListItem.Delete</a> or <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.recycle.aspx" rel="nofollow noreferrer">SPListItem.Recycle</a> to remove the item.</p> <p>Here's an example that uses SPQuery:</p> <pre><code>[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") $site = new-object Microsoft.SharePoint.SPSite("http://yoursite/") $web = $site.OpenWeb("Web Title") $documentLibrary = $web.Lists["Document Library Name"] $yesterdaysDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([System.DateTime]::UtcNow.AddDays(-1.0)) $query = new-object Microsoft.SharePoint.SPQuery $query.ViewFields = "&lt;FieldRef Name='Modified' /&gt;" $query.Query = "&lt;Where&gt;&lt;Leq&gt;&lt;FieldRef Name='Modified' /&gt;&lt;Value Type='DateTime' IncludeTimeValue='TRUE'&gt;" + $yesterdaysDate + "&lt;/Value&gt;&lt;/Leq&gt;&lt;/Where&gt;" $queryItems = $documentLibrary.GetItems($query) foreach ($item in $queryItems) { echo $item.Url $item.Delete() } $web.Dispose() $site.Dispose() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload