Tuesday, May 7, 2013

Project Server 2010 Workflow - AppSettings Part II

In one of my previous posts, I've shown how to read Application Settings from workflow. 

But, that isn't always the best practice. It isn't recommended for users to edit machine.config, especially if you need to store a large amount of data in Application Settings.

Instead of tampering with machine.config, you can just open new SharePoint site in your workflow and instance configuration file of that Web Application. Here is how:





using (SPSite site = new SPSite(contextInfo.SiteGuid))
{
      System.Configuration.Configuration _config = WebConfigurationManager.OpenWebConfiguration("/", site.WebApplication.Name);
      
      string _MySetting = _config.AppSettings.Settings["MySettingName"].Value;
                   
}


Now, in a very simple way, we have read value of setting ("MySettingName") stored in Application Settings of our Web Application.

No comments:

Post a Comment