Sean Wallbridge, SharePoint MVP


RSS Feed Feed your read!

The Lowdown

Sean's Resume
itgroove (Victoria, BC)
Major Change
Beer Me! (Donate)
Sean's SharePoint Ditty
About Sean
SharePoint Best Practices
Recommended Reading
Follow me on Twitter
Aggregated MVP Blogs

Search

Archives

August 2010 (4)
July 2010 (6)
June 2010 (4)
May 2010 (16)
April 2010 (20)
March 2010 (11)
February 2010 (3)
January 2010 (4)
December 2009 (6)
November 2009 (5)
October 2009 (14)
September 2009 (15)
August 2009 (11)
July 2009 (14)
June 2009 (20)
May 2009 (19)
April 2009 (22)
March 2009 (20)
February 2009 (19)
January 2009 (13)
December 2008 (8)
November 2008 (16)
October 2008 (16)
September 2008 (16)
August 2008 (11)
July 2008 (5)
June 2008 (8)
May 2008 (14)
April 2008 (18)
March 2008 (31)
February 2008 (13)
January 2008 (10)
December 2007 (4)
November 2007 (2)
October 2007 (9)
September 2007 (10)
August 2007 (4)
July 2007 (10)
June 2007 (7)
May 2007 (13)
April 2007 (8)
March 2007 (1)
February 2007 (2)
January 2007 (11)
December 2006 (2)
November 2006 (10)
October 2006 (7)
September 2006 (5)
August 2006 (6)
July 2006 (5)
June 2006 (5)
May 2006 (5)
April 2006 (7)
March 2006 (2)
February 2006 (3)
January 2006 (9)
December 2005 (4)
November 2005 (19)
October 2005 (6)
September 2005 (15)
July 2005 (5)
June 2005 (3)
May 2005 (4)

Links

itgroove Website
BrainLitter Archive
SharePoint Team Blog
Sean's SharePoint Ditty
WSS 3.0 Builds
MOSS 2007 Builds
MVP Profile
MCP Virtual Transcript
2010 Product Comparison

Tag Cloud

Active Directory, ASP.NET, Best Practices, CKS Enhanced Blog Edition, Exchange, From the Brain, IIS, ISA, itgroove, MOSS 2007, Outlook, Rants, Response Point, SBS, Security, SharePoint, SharePoint 2010, SharePoint Designer, SQL Server, Terminal Services, Toronto Maple Leafs, VMware, Web Litter, Windows, Windows 7, Windows Server 2008, Windows Vista, WSS 3.0,

Delightfully Simple - How to delete files in a document library after x hours, days or months 

Tags: MOSS 2007, SharePoint, SharePoint Designer, WSS 3.0

This question came up on Experts-Exchange.com today and after a few minutes of consideration, here's my suggestion to the problem – simple, effective and customizable … and better yet, no code! More importantly, I hope this helps inspire ideas and creativity, by demonstrating how simple this really was, to implement.

 

The Business Requirement

 

We have a 3rd party application which sends daily reports (PDF's) to a document library every day. Is there any other way we can delete reports older than a week automatically?

 

Assumptions

 

I am making one assumption here and that is that this document library is *dedicated* to storing just these PDF reports. If this library was used to store all sorts of documents, for other purposes as well (perhaps the PDF's were stored in a single folder, within the document library?), we would need to add some additional logic such as checking the type of file, etc. and exiting out of the workflow if it wasn't a 'daily report' PDF.

 

The Solution

 

A simple SharePoint Workflow, created in SharePoint Designer (remember, SPD is free now – get it at http://www.microsoft.com/spd - of course, proceeding with caution). Here are the steps to solve this particular requirement

 

  1. Create a SharePoint Designer Workflow that fires against newly created/edited items in the document library
  • Again, if this library is storing other types of documents as well, you will want to abort the workflow upon detecting that type of document
  1. Use the Pause Action to 'wait' until a week passes
  2. That's it

 

If you wanted to, particularly for testing in the early going, you might want to write out history and/or email yourself to notify that the file has been deleted, to ensure it is working as expected. You'll want to remove that action however, once you get the workflow going the way you want it.

 

The Visual Overview of the Solution

 

First off, we need a document library. Oh, good, here's one!

 

 

Now we need to connect to our SharePoint site, using SharePoint Designer. Get SPD at http://www.microsoft.com/spd. Once it is installed, connect to your SharePoint site by choosing File, Open Site and plunking in the URL to the site (not to the library), such as http://portal.somewhere.com

 

 

 

 

Next, we need to create a new SharePoint Workflow. Note, you may get prompted to download and install the Windows Workflow Foundation before you can proceed. If you get that, er, do it, eh?

 

Choose File, New… Workflow…

 

 

Give the workflow a meaningful name, choose the correct library to fire against and choose the option to run against newly created items

 

 

Click Next and then create the first step, to pause for 7 days (using the Pause for Duration Action) and give this first step a meaningful name

 

 

Note: if the Pause for Duration Action isn't in the dropdown list, simply choose the More Actions button (it likely won't be, if you haven't created any previous workflows)

 

 

 

Now, set the Pause for Duration to be the length of time you wish to wait, to delete the item. I'd suggest when you initially test the item, to set this to 5 minutes, so you don't have to wait too long to test your results :-) … see below for how to modify an existing workflow.

 

Add a 2nd workflow step, to handle the 'Delete' function (which would run, once the Pause for Duration time period has passed)

 

 

Give the 2nd step a descriptive name, and an action of 'Delete Item'. Then select the hyperlink that says 'This List' and choose the 'Current Item'.

 

 

The 2nd step should look like the following, when complete.

 

 

The Workflow will validate and we'll be in business.

 

 

Testing the Workflow

 

As mentioned, you may want to set your 'Pause for Duration' to be 5 minutes, instead of 7 days, until you are sure this baby is ready to roll. To test the workflow, add a new document to the library in whatever method you require (upload, WebDav/Publish, Email to Library, etc.).

 

You should notice that…

 

  • The document is gone after the 5 minutes has elapsed (ok, I'm really impatient and went for 2 minutes)

 

 

 

  • And in case you were curious… yes, it still sticks it in the Recycle Bin, where it should.

 

 

How to Modify an Existing Workflow

 

Finally, if you wanted to modify the workflow after the fact (alter the timeframe, say from the 5 minute test, to the 7 day requirement, it is easy to find and reopen/edit your workflow. Simply double click the .XOML file, under Workflows and then the name of your workflow (in our case, it was 'Delete Daily Reports Older than 1 Week).

 

 

One final note. Don't you hate when you try to write something original but then realize someone else had written the same damn thing, before you (honestly, this wasn't lifted... I'm the first to even bring it up too :)

 

Anyways, props to these folks, who solved the same problem, the same way...  a long time before I did... http://www.sharepointblogs.com/holliday/archive/2007/07/26/delete-files-using-workflow-using-duration.aspx

 

 

 
Posted by Sean Wallbridge on 28-Jul-09
Bookmark this post with:        
 

Comments


Gerald Weibl commented on Wednesday, 29-Jul-2009
You can also use the "Expiration policy" to delete the document after 1 week, so you don't need a workflow which waits for 1 week.


Gerry Brimacombe commented on Wednesday, 29-Jul-2009
Great Stuff, Sean. I also saw a solution to this problem done by creating a calculated field the the DocLib [Add-Date + 7], and using a View to filter out the "expired" files. Yes, this doesn't exactly solve the client's problem, because it doesn't acutally delete...but it's simple.


Sean Wallbridge commented on Wednesday, 29-Jul-2009
Hey Gerald, Thanks for the note. That's true but will require 'more work' (this was a 'simple solution) as Information Rights Management will need to be configured/installed (particularly in the case of a WSS site). As well (and IRM isn't my particular area of expertise), we would need to define what content types to apply that expiration policy against - and the problem with that is, how do we determine, in this scenario, where emails come in to an email enabled document library, which documents can then be deleted (expired) and which one's shouldn't - then again, this sounds like a job for a dedicated document library for the purpose of status reports and not one that should be combined with other tasks.


Jason Gambill commented on Thursday, 13-Aug-2009
Interesting solution and comments. I've been trying to solve this myself with the integrated item expiration using the created date +X days, and although the items are flagged as expired, they simply aren't being deleted. Sean, your comment about using a dedicated document library scares me a bit - we were thrown Sharepoint without any instruction, and used forms to create monster lists (600+ entries daily) in order to produce reports. We probably went about that all wrong, but who knew. Anyhow, I'm going to continue poking away until I've figured out why these things just won't delete.

blog comments powered by Disqus