Skip to main content
I'm generating Code from K2 Studio in the Destination Rule. How can I access the config file to store my settings like appSettings and Database settings? Is there a way to do this other than hardcoding those values w/in the generated Code section?
Have you considered using K2.StringTable("field value")?
You can store different values per environment.

Otherwise there are .NET methods that can retrieve from Appsetting.
Thanks Peter - would you have sample code of referencing appsetting?


To access settings in the configuration file at runtime, you can use the following code:

Dim MyKeySetting as String = System.Configuration.ConfigurationSettings.AppSettings.Get("MyKey")


NOTE: the settings in the config file are read ONCE at K2 Server startup, so if any setting needs to be changed in the file, you'll need to restart K2Server so that it can pick up the new settings.

If your settings are stored in a string table, you don't need to restart K2Server, since the settings are read from the string table each time you access them in code.

HTH

Hehe...
Since Neil has already stolen Peter's spot in the sun, I'll add my 2c worth...

If I'm not mistaken, pre-SP4 (K2.net 2003) systems could make use of custom sections (sections outside 'AppSettings') but I have not been able to add custom sections to an SP4 system - no idea why yet!!

Since it is NOT an officially supported feature, I would love to hear from anybody who have been able to do this - Peter, here's your chance again...

Regards,
Ockert
I am not using the .CONFIG method, just StringTable.
Neil - thanks for the info. I just tried it but I'm getting an error. i'm using the K2Rom in VS2005. I know the way to reference appsettings is slightly different in 2005. This is the error I'm receiving. Any ideas what I'm doing wrong here?

The type or namespace name 'ConfigurationSettings' does not exist in the namespace 'System.Configuration'

I'm customizing the desination rule code in one of my activities when I reference this to get the connection string and reading usernames from a db table:

.ToString(); 
// add the user to the K2 Destintion
K2.Destinations.Add(DestinationType.User, strUserName);
}
// close the reader
dbRdr.Close();
// discard the command
dbCmd.Dispose();
this.IsSuccess = true;
}
catch (Exception ex)
{
throw(ex);
this.IsSuccess = false;
}

}

Things changed a bit with .NET 2.0.

You'll first need to add a Project reference to "System.Configuration" within K2 Studio. To add a reference in K2 Studio:

1. Right click on the project name in Solution Explorer and select Properties.
2. Select "References" in the left pane
3. Click the "Add" button
4. In the ".NET" tab scroll down to "System.Configuration" and select it, then click OK.
5. You should now see "System.Configuration.dll" in the Component Name column.

Once this reference has been added, you'll need to change your code slightly to resemble the following (notice the new .NET 2.0 method of calling config settings):


String strDbConn = System.Configuration.ConfigurationManager.AppSettings.Get("DbConnection");



You should now be able to compile.

Generally speaking, app config files are only required if there is a custom .NET assembly being used within K2; otherwise the K2 String Table is typically utilized, as Peter pointed out earlier. Since you are looking to retrieve this setting for use within a K2 Destination Rule, not an external assembly, both techniques should work, but the use of String Tables generally consolidates environmental settings thus making maintenance easier (as they can be modified via K2 Service Manager).
Odd... I don't see system.configuration as a selection. I then proceeded to browse for it under C:WINDOWSMicrosoft.NETFrameworkv2.0.50727 selected it and then hit ok

and got this error in K2 Studio:

Exception from HResult: 0x80040202

followed by another message box:

Object Reference not set to an instance of an object

followed by another message box:

C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.configuration.dll is not a valid ActiveX Object

Any ideas?

Thanks!

Vinny,

It sounds like your K2 Studio is configured to use .NET 1.1 not 2.0.

You should change the K2Studio.exe.config file (in ...Program FilesK2.netBin) to the following:


<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>


Then restart K2.net Studio and retry the reference.

Reply