Showing posts with label Feature Activation. Show all posts
Showing posts with label Feature Activation. Show all posts

Wednesday, October 27, 2010

Activate and DeActivare Feature by Programmatically in Sharepoint 2007

How to Activate and DeActivate Features by programmatically (C#) in Sharepoint 2007?

Activate Feature:

A feature can be activated through Programmatically as follows.

private void ActivateFeature(Guid guid)

{

try

{

SPFeature spFeature = site.Features[guid];

if (spFeature == null)

{

site.Features.Add(guid);

}

}

catch (Exception ex)

{

MessageBox.Show("Activate : " + ex.Message);

}

}

DeActivate Feature:

A feature can be DeActivated programmatically as follows.

private void DeActivateFeature(Guid guid)

{

try

{

SPFeature spFeature = site.Features[guid];

if (spFeature != null)

{

site.Features.Remove(guid);

}

}

catch (Exception ex)

{

MessageBox.Show("DeActivate : " + ex.Message);

}

}