jEyLaBs – A proven provider of IT Services and Solutions

Accessing K2 Environment library via code

K2’s environment library is a great feature allowing you to have a server based config file which can be used by K2 process applications or if you wish other applications as well. K2 workspace allows for the management of this library.

If you want to access this library from your application via code this is what you have to do:

In your .NET app, Add references to the K2 EnvironmentSettings.Client and the SourceCode.Hosting.Client DLLs.

include the following using statements.

using SourceCode.EnvironmentSettings.Client;
using SourceCode.Hosting.Client.BaseAPI;

However this code block will require Admin permissions on K2. I recommend using the Environmentclient API for read access.

If you want to access the environment from within a K2 process though it is pretty easy. The configuration screens allows you to drag and drop a variable from the object browser. If you want to access a field from within a server event you can simply write this line of code:

string env_field_value = K2.StringTable[“env field name”];

Since the context “K2″ is passed in to the server event accessing anything from the context such as environment variables becomes very easy.

Access to environment variables can be controlled through K2 workspace by setting permissions. This allows for control over who gets to read/write what template fields.

Jey is a seasoned SharePoint consultant and a K2 Insider located in Melbourne, Australia. With over a decade
of IT consulting experience, He founded jEyLaBs in early 2009.
jEyLaBs is a K2 service provider partner focused on delivering process driven IT
solutions using K2, SharePoint and related technologies. Jey is ex-K2 and has
been working with K2 technology since early 2006. During the early years of
SharePoint consulting he found K2 to be a great platform to deliver workflow to
the masses through SharePoint. Now working through his teams in Australia and
SriLanka, Jey and jEyLaBs help implement effective solutions to process
problems.