1,758 articles and 13,594 comments as of Tuesday, November 9th, 2010

Wednesday, November 3, 2010

QOTD: SharePoint Document Library

Author: Eric Alexander, Moderator, Stump the Panel

The Question of the Day from Stump the Panel came in regarding document libraries in SharePoint:

Wendy writes:

I have a document library that I created to share files with clients that are too large to e-mail. It will never be used for long-term storage, and I don’t want the files in it to get forgotten and take up valuable storage space, so I would like to set up some kind of workflow that will automatically delete a folder and all files within it two weeks after creation. Here are the restrictions I am working within:

  • I would like to avoid using SPD if possible (our SP support team has said they won’t fix anything broken if we have ever touched our site with SPD)
  • I would ideally like to be able to delete an entire folder and its contents, not just individual files
  • We already have corporate-defined document retention policies set up for us, so I can’t handle this that way
  • We have MOSS 2007

Any thoughts?

Thanks!

Wendy — STP

————-

Both Kerri and I agree that the only out of the box option to automate the process is to use Information Policy Management within the document library leveraging content types for folders and documents. The challenge would be if these documents could be exempted from the corporate policy, if they cannot, then using IRM wouldn’t work. If that couldn’t be done, then manual cleanup will be needed.

As a personal aside, when will IT staves get over this whole SPD nonsense? Yes, it has the potential to be damaging, but you do have a backup plan in place right? Limiting the functionality of the product not only reduces end user buy in, but also severely impacts any sort of return on investment. There are tons of resources available for SPD training. Plan, govern, and train and you’ll have happy employees, see adoption increase, and see a larger return on your SharePoint investment.

To set up IRM on the document library:

  1. Go into the document library settings.
  2. From this menu, you’d want to hit the radio button Define a Policy and click OK.
  3. Tick the check box for Enable Expiration.
  4. Set the Time period to Created plus 14 days.
  5. Set the action to Delete.
  6. Click OK.

Matt offers an alternative approach with the Explorer View and a script.

Option Explicit

Const strFrom = "[email protected]"
Const strTo = "[email protected]"
Const strMailserver = "smtp.domain.com"
Const strSchema = "http://schemas.microsoft.com/cdo/configuration/"

Dim objFSO, objFolder, objEmail
Dim colFiles
Dim file, Subject, Body, strError

set objFSO = Wscript.CreateObject("scripting.FileSystemObject")
set objFolder = objFSO.GetFolder("\\server\share")
set colFiles = objFolder.Files

For Each file in colFiles
   If DateDiff("d", file.DateLastModified, Now) >= 14 Then
      ON ERROR RESUME NEXT
      file.Delete
      ON ERROR GOTO 0
      If Err.Number <> 0 Then
         Call ErrHandler("FTP AUTO DELETE FAILED!", "Number = " & err.Number & " Description = " & err.Description & " Source = " & err.Source)
      End If
   End If
Next

Call SendEmail("FTP AUTO DELETE SUCCESSFUL", "All expired files were deleted.")

Sub ErrHandler(Subject, strError)

   err.Clear

   Call SendMail(Subject, strError)
End Sub

Sub SendEmail(Subject, Body)
   Set objEmail = CreateObject("CDO.Message")
   objEmail.From = strFrom
   objEmail.To = strTo
   objEmail.Subject = Subject
   objEmail.Textbody = Body
   objEmail.Configuration.Fields.Item _
       (strSchema & "sendusing") = 2
   objEmail.Configuration.Fields.Item _
       (strSchema & "smtpserver") = strMailserver
   objEmail.Configuration.Fields.Item _
       (strSchema & "smtpserverport") = 25
   objEmail.Configuration.Fields.Update
   objEmail.Send

   Call Cleanup
End Sub

Sub Cleanup

   set objFSO = nothing
   set objFolder = nothing
   set objEmail = nothing
   set colFiles = nothing
   set file = nothing
   set Subject = nothing
   Set Body = nothing
   Set strError = nothing

   WScript.quit
End Sub

Author: Eric Alexander, Moderator, Stump the Panel

Eric Alexander is a SharePoint Administrator working in the Higher Education sector. He wears many hats in this role and enjoys leveraging SharePoint to build solutions to solve problems across campus. You can find him on Twitter as PirateEric and lurking in the Stump the Panel forums.
http://feeds.feedburner.com/EricsSharepointAdventures

 

Please Join the Discussion

3 Responses to “QOTD: SharePoint Document Library”
  1. Matt Bramer says:

    It should be noted, that this script is a VBScript. When you copy the text, make sure the extension you use is:
    .vbs

    You can also set this to run every day in your Task Scheduler. As long as you have permissions to open the Doc Library up in Explorer view, this whole process can be automated.

  2. Mike Bunyan says:

    Nice script and idea of this problem.
    My concern would be that if used with recurs through folders it would delete the aspx files in the ‘Forms’ folder that provide the display for lists.

    I thought it would be relatively straight forward to create a view that lists file with certain age, which the user can then select and delete. A bit tedious if there are many.

    or create a folder with a date prepended to drop files into, drop a text file into it with a standard workflow ‘review’ reminder to so something.

  3. Matt Bramer says:

    Hi Mike Bunyan,

    I developed this script to manage an anonymous uploads folder for an FTP site. When you set this script to the shared folder, it’ll only delete files; not folders. That’s the behavior for this script on a file server, so I would expect it to be the same on SharePoint.

    Try it out on a test Doc Library and let me know what happens!


Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!