Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Putting Multiple Items on Hold in SharePoint Server 2007

SharePoint 2007

Summary:  Learn how to programmatically apply a hold to all items in a folder in a records center in Microsoft Office SharePoint Server 2007.

Office Visual How To

Applies to:  2007 Microsoft Office System, Microsoft Office SharePoint Server 2007

Microsoft Corporation

March 2008


The records center in Microsoft Office SharePoint Server 2007 lets you define and apply holds to records. Applying a hold prevents records from going through disposition, which means that all expiration policies are suspended until the hold is removed. In the records center, you can apply holds to individual records or to all records that are returned in a search result. This Microsoft Office Visual How To shows you how to programmatically apply a hold to all items in a folder.

Code It

The code example in this section assumes that the following items are set up in an Office SharePoint Server records center site:

  • The records center site is created at http://localhost/records.

  • A library named Financial Statements is created in the records center site.

  • A folder named FY 06 (referring to fiscal year 2006) is created in the Financial Statements library.

  • Files are uploaded to the FY 06 folder.

  • An item (any values for Title / Description / Managed By) is added to the Holds list in the records center.

Interaction with the Holds API is performed through the Hold class in the Microsoft.Office.RecordsManagement.Holds namespace, which is in the Microsoft.Office.Policy assembly. You must reference this namespace, together with the Microsoft.SharePoint namespace, as shown in the following example.

using Microsoft.SharePoint;
using Microsoft.Office.RecordsManagement.Holds;

The Hold class contains a SetHold method, which you use to apply the hold. In this case, you use the SetHold signature that accepts an SPListItemCollection object, which is the collection of items in the FY 06 folder that you want to place on hold.

First, you must obtain the ID of the hold you want to apply. The holds are described as list items in the Holds list. Here, you are getting the first item in the Holds list. Then you obtain the collection of list items to which you want to apply the hold. The following example retrieves this collection by executing a query on the Financial Statements list for all items in the FY 06 folder.

using (SPSite site = new SPSite("http://localhost"))
    using (SPWeb web = site.OpenWeb("/records"))

        // Get the hold item.
        SPList holdList = Hold.GetHoldsList(web);
        SPListItem holdItem = holdList.Items[0];
        int holdID = holdItem.ID;

        // Get the list and folder.
        SPList list = web.Lists["Financial Statements"];
        string folderUrl = 
        "http://localhost/records/financial statements/FY 06";
        SPFolder folder = web.GetFolder(folderUrl);

        // Set up and execute the query.
        SPQuery query = new SPQuery();
        query.ViewAttributes = "Scope='Recursive'";
        query.Folder = folder;
        SPListItemCollection listItems 
        = list.GetItems(query);

        // Apply the hold.
        Hold.SetHold(holdID, listItems, 
        "Programmatically added hold to folder items ");

After you obtain the collection of list items, you apply the hold by calling the SetHold method and passing in the ID of the hold, the collection of items in the FY 06 folder, and comments about the hold. Office SharePoint Server automatically adds a Hold Status column to the list if the column is not already present, and it sets the status to On Hold when the hold is applied.

Read It

In addition to the visible Hold Status that is set, the holds framework internally marks the item as having a hold applied. At this point, nothing more is needed to ensure that the policy framework does not accidentally delete the item if the item is up for expiration. All expiration policies are suspended for the held records while the hold is in place. After the hold is removed, the expiration policies resume.

Programmatically removing a hold, which is similar to applying a hold, uses the RemoveHold method, as shown in the following example.

Hold.RemoveHold(holdID, listItems, 
"Programmatically added hold to folder items ");

The query in this example is limited to all items in the FY 06 folder. You do this by setting the Folder property. In addition, setting the ViewAttributes property to "Scope=’Recursive’" causes all items in the FY 06 folder and any items in subfolders to be returned in the list item collection.

To fully implement this example, it might make sense for you to add a custom .aspx page. This page, which derives from the existing Hold.aspx page, enables users to select folders to place on hold. In addition, you can extend the hold report that is generated to include the folders that were placed on hold.

See It

Put Items on Hold in SharePoint Server 2007

Watch the Video

Video Length: 00:05:29

File Size: 3.62 MB WMV

Explore It

Community Additions

© 2015 Microsoft