SIGN UP MEMBER LOGIN:    
ARTICLE

Programmatically enable Enterprise keywords in SharePoint 2010

Posted by Vijai Anand Articles | SharePoint June 03, 2011
In this article we will be seeing how to enable Enterprise keywords for a list using SharePoint object model.
Reader Level:

Introduction: 

Enterprise keywords are used to tag the documents when uploading the documents in the document library. Enterprise documents can be enabled in both SharePoint lists and libraries. Enterprise keywords - Terms are stored in a non-hierarchical way and available for users to key in which is known as folksonomy (free tagging). In this article we will be seeing how to enable Enterprise keywords for a list using SharePoint object model.

Prerequisites:
  1. Managed metadata service application should be configured. 

  2. Web application should be associated to the Managed Metadata Service Application.
Programmatically Enable Enterprise Keywords:

To enable Enterprise keywords through UI refer http://www.c-sharpcorner.com/UploadFile/anavijai/7633.

To enable enterprise keywords using object model do the following steps:
  • Open Visual Studio 2010. 

  • Go to File => New => Project. 

  • Select Console Application template from the installed templates. 

  • Add the following references.

    Microsoft.SharePoint 

  • Add the following namespaces.

    using Microsoft.SharePoint;

  • Replace Program.cs with the following code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    namespace EnterpriseKeywords
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (SPSite site = new SPSite("http://serverName:22222/sites/Test/"))
                {
                    using (SPWeb web = site.OpenWeb("BL"))
                    {
                        SPList list = web.Lists.TryGetList("dl");
                        if (list != null)
                        {
                            SPField field = list.ParentWeb.AvailableFields["Enterprise Keywords"];
                            if (!list.Fields.ContainsField("Enterprise Keywords"))
                            {
                                list.Fields.Add(field);
                                list.Update();
                                Console.WriteLine(field.Title + " added successfully to the list");
                            }
                            else
                            {
                                Console.WriteLine(field.Title + " column already exists in the list");
                            }
                        }
                        else
                        {
                            Console.WriteLine(list.Title + " does not exists in the site");
                        }
                        Console.ReadLine();
                    }
                }
            }
        }
    }

  • Build the solution.

  • Hit F5.

  • Go to the =>Permissions and Management => Enterprise Metadata and Keywords Settings.

  • You could see the "Enterprise Keywords" enabled.

    Enterprisekeywords1.jpg

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor