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"); } } } } } } }
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: