top of page
Writer's pictureVijai Anand Ramalingam

How to Release a hold using PowerShell and programmatically in SharePoint 2010

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

In this article

  • Release a hold using c#

  • Release a hold using PowerShell

Release a hold using c#:


a. Open Visual Studio 2010.

b. Create a new console application.

c. Add the following references. i) Microssoft.Office.Policy.dll

ii) Microsoft.SharePoint.dll

d. Add the following namespaces. i) using Microsoft.SharePoint;

ii) using Microsoft.Office.RecordsManagement.Holds;

e. Replace the code with the following.

  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Text;

  5. using Microsoft.SharePoint;

  6. using Microsoft.Office.RecordsManagement.Holds;

  7. namespace Holds

  8. {

  9. class Program   

  10. {

  11. static void Main(string[] args)       

  12. {          

  13. using (SPSite site = new SPSite("http://serverName:1111/"))           

  14. {

  15. using (SPWeb web = site.RootWeb)               

  16. {

  17. //Release a Hold

  18. SPList list = web.Lists["Holds"];

  19. SPListItem item = list.Items[0];

  20. Hold.ReleaseHold(item, "Release the hold");               

  21. }           

  22. }       

  23. }   

  24. }

  25. }

Release a hold using PowerShell:

  1. $siteURL="http://serverName:1111/"

  2. $site=Get-SPSite $siteURL

  3. $web=$site.RootWeb

  4. $list = $web.Lists["Holds"]

  5. $item=$list.Items[0];

  6. [Microsoft.Office.RecordsManagement.Holds.Hold]::ReleaseHold($item,"Release the Hold")

  7. $web.Dispose()

  8. $site.Dispose()

0 comments

Comments


bottom of page