It’s a common conundrum, I at least need to store the K2 HostServer and HostServerPort to do anything I want to. People use the web.config, config lists, and even access K2’s hidden list in SharePoint. Keep in mind that up until now, in my opinion, the hidden lists were the best option, but they’ve been risky and needed regression testing after each upgrade. Like the database tables, the hidden SharePoint objects are subject to change without notice in an update.
Here is the solution: (thanks to K2/SourceCode’s Rob Joy and Leon Geldenhuys for the heads up and explanation)
Basically two lines of code and you have the K2 settings that are appropriate for the site context you are in, per the administrators configuration:
The K2 help files already contain an article on the administration side. Summed up in this screenshot, note that I’ve chosen to “Update settings for all sub webs” (circled). Most of the time you will want this checked because you won’t have 2 or 3 K2 farms out there that are specific to sub webs.
Here is the code I used. Just reference Microsoft.SharePoint (browse) and SourceCode.SharePoint (“.net” or from the GAC) libraries and have fun!