SIGN UP MEMBER LOGIN:    
ARTICLE

How to remove from a hold using PowerShell and programmatically in SharePoint 2010

Posted by Vijai Anand Articles | SharePoint March 14, 2011
This description is about how to remove from a hold in SharePoint 2010 using PowerShell and C#.
Reader Level:

In this article we will be seeing how to remove from a hold in SharePoint 2010 using PowerShell and C#.

Refer http://www.c-sharpcorner.com/UploadFile/anavijai/5103/ to create a hold and add or remove the hold to the item through UI.

In this article

  • Remove from a hold using c#
  • Remove from a hold using PowerShell
Remove from a hold using c#
  • Open Visual Studio 2010.
  • Create a new console application.
  • Add the following references.

        1) Microsoft.Office.Policy.dill
        2) Microsoft.SharePoint.dill

  • Add the following namespaces.

        1) using Microsoft.Sharepont;
        2) using Microsoft.Office.RecordsManagement.Holds;
        

  • Replace the code with the following.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.Office.RecordsManagement.Holds;
namespace Holds
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://serverName:1111/"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    //Removes the specified item from the specified hold
 
                    SPList list = web.Lists["Shared Documents"];
                    SPListItem item = list.Items[0];
                    SPList listHolds = web.Lists["Holds"];
                    SPListItem itemHold = listHolds.Items[1];
                    Hold.RemoveHold(item, itemHold, "Hold removed"); 

                    //Removes the specified items from the specified hold.  
                    SPListItemCollection items = list.Items;
                    Hold.RemoveHold(items, itemHold, "Hold Removed from all the items"); 
                }
            }
        }
    }
}

Removes the specified item from the specified hold:

pic1.gif
Removes the specified items from the specified hold:

pic2.gif
Remove from a hold using PowerShell

Removes the specified item from the specified hold:

$siteURL="http://serverName:1111/"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$list = $web.Lists[
"Shared Documents"];
$item = $list.Items[0];
$listHOlds = $web.Lists[
"Holds"]
$itemHold=$listHOlds.Items[0];
[Microsoft.Office.RecordsManagement.Holds.Hold]::RemoveHold($item,$itemHold,
"Hold removed")
$web.Dispose()
$site.Dispose()

Removes the specified item from the specified hold:

$siteURL="http://serverName:1111/"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$list = $web.Lists[
"Shared Documents"];
$items = $list.Items;
$listHOlds = $web.Lists[
"Holds"]
$itemHold=$listHOlds.Items[0];
[Microsoft.Office.RecordsManagement.Holds.Hold]::RemoveHold($items,$itemHold,
"Hold removed from all the items")
$web.Dispose()
$site.Dispose()


Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor