Jaa


How to: Remove a Configuration Setting

The following procedure demonstrates how you can remove a configuration setting that you created through the Application Setting Manager.

To remove a configuration setting

  1. Add a reference to the SharePoint Guidance Library assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add References. Click the Browse tab, and then navigate to the location of the Microsoft.Practices.SharePoint.Common.dll assembly.

  2. Using the same procedure, add a reference to the Microsoft.Practices.ServiceLocation.dll assembly.

  3. Add the following using statements to the top of your source code file.

    using Microsoft.Practices.ServiceLocation;            
    using Microsoft.Practices.SharePoint.Common.Configuration;
    using Microsoft.Practices.SharePoint.Common.ServiceLocation;
    
  4. Use the SharePointServiceLocator.GetCurrent() method to get a reference to the current service locator instance.

    IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();
    
  5. Use the service locator to request an implementation of the IConfigManager interface.

    IConfigManager configManager = 
     serviceLocator.GetInstance<IConfigManager>();
    
  6. (Optional) If your code is running in an environment where the SPContext.Current property is not available, call the SetWeb method and pass in an SPWeb object from which to build the storage hierarchy. If a SharePoint context exists, you can skip this step.

    configManager.SetWeb(web);
    
  7. Retrieve the IPropertyBag instance from which you want to remove your application setting.

    IPropertyBag bag =   
           configManager.GetPropertyBag(ConfigLevel.CurrentSPWebApplication);
    
  8. Call the IConfigManager.RemoveKeyFromPropertyBag method. The first parameter is the key string that you originally used to identify your configuration data. The second parameter is the IPropertyBag object in which the configuration setting is stored.

    configManager.RemoveKeyFromPropertyBag("MyApplication.LastUpdate",                                
            bag);