In this article we will be seeing how to set hold to documents based on Metadata values in SharePoint 2010. In "Shared Documents" I have created metadata column "Metadata Col". Based on the metadata value documents will be set to hold. Shared Documents has the following documents and documents having the "Metadata Col" value as "Friday" will be set to hold. Steps Involved:
namespace Holds { class Program {
static void Main(string[] args) { using (SPSite site = new SPSite("http://serverName:22222/sites/TestSite/")) { using (SPWeb web = site.RootWeb) { SPList list = web.Lists["Shared Documents"]; SPListItemCollection itemColl = list.Items; foreach (SPListItem item in itemColl) { string value = item["Metadata Col"].ToString(); string[] metadataValues = value.Split('|'); if (metadataValues[0] == "Friday") { SPList listHolds = web.Lists["Holds"]; SPListItem itemHold = listHolds.Items[0]; Hold.SetHold(item, itemHold, "Hold added"); } } } } } } }