I have application that adds a Farm feature so Sharepoint 2010. When you configure it, some entries are added to the web.config file located in "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebServices\SecurityToken" Whenever I deactivate the farm feature from the Sharepoint Central Administration interface (System Settings\Manage Farm Features) those entries will be deleted properly from the web.config file. The problem I have is that I want to be able to deactivate the feature programatically so I built an uninstaller that will deactivate all the features created by my .wsp and retract and remove the solution, but when it deactivates the farm feature, the entries made to the web.config file that I previously mentioned are not deleted. I use the folowing line to deactivate the feature :

SPWebService.AdministrationService.Features.Remove(feature.Definition.Id, true);

Let me know if you got any idea or need more information. Thanks.

1 Answer 1



Since you are removing feature programmatically, you can use SPWebConfigModification to remove web config settings programmatically too!

Here is a nice article:
SharePoint: How to use SPWebConfigModification class

I hope this helps

  • Thanks a lot for the answer! I've had a look at the application that I wished to uninstall programmatically and I finally found out that the problem was that it used SPContext in order to delete those specific web.config modification. So when my external application tried to deactivate the feature, SPContext was null so that part of the code didn't execute at all. I don't have enough rep to upvote your answer but thanks a lot anyways.
    – Alex
    Nov 29, 2012 at 20:04
  • No problem, glad it helped! Nov 29, 2012 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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