0
using System;
using SPTool.Library;
namespace ConsoleApplicationExmFeature
{
    class Program
    {
        static void Main(string[] args)
        {

            SPTSite site = new SPTSite("http://itcdev33");

            // Activate site collection scoped feature
           // SPTReturn returnObj = site.ActivateFeature("SPTool.Site.Config", false);

            // Activate site collection scoped feature using Guid
             SPTReturn returnObj = site.ActivateFeature("32529c03-833d-4c5e-a15e-0bcb35bdedad", false);

            // Check the status of Activating the feature
            if (returnObj.State == SPTState.Success)
            {
                // Activating Feature Successful
                Console.WriteLine("Activating Feature Successful");
            }
            else
            {
                // Activating Feature Failed
                Console.WriteLine("Activating Feature Failed");
            }

        }
    }
}
  • I have already added an assembly reference and deployed the assembly in gac, still getting an error while compiling. – Niranjan Kulkarni Feb 28 '14 at 5:59
1

You don't need this library if all you want is to activate a feature. Just add reference to Microsoft.SharePoint dll and following is the code sample to activate a web scoped feature:

static void Main(string[] args)
{

    using (SPSite site = new SPSite("http://itcdev33"))
    {
        SPWeb web = site.RootWeb;
        web.AllowUnsafeUpdates = true;
        Guid featureGuid = new Guid("32529c03-833d-4c5e-a15e-0bcb35bdedad");
        web.Features.Add(featureGuid);
        web.AllowUnsafeUpdates = false;
    }           
}   

To add reference to Microsoft.SharePoint dll, Right Click on Project Reference, Select Add Reference, Click on Browse and browse to folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI in case of SP 2013 and if it is SP 2010 use 14 instead of 15 in folder name and select Microsoft.SharePoint.

enter image description here

  • Now I am getting this error.The type or namespace “Sharepoint” name does not exist in namespace Microsoft (are you missing a using directive or an assembly reference)? Though I have deployed the assembly and added reference. – Niranjan Kulkarni Mar 4 '14 at 9:03
  • See my updated answer. – Nadeem Yousuf Mar 4 '14 at 9:11
  • Sorry sir, still getting that same error. – Niranjan Kulkarni Mar 4 '14 at 11:09
  • Adding using Microsoft.SharePoint; at top of the file. – Nadeem Yousuf Mar 4 '14 at 11:12
  • I am using VS2010 – Niranjan Kulkarni Mar 4 '14 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.