This is part of a set of "snippet" posts that I'm going to try and write more often, these posts are (hopefully) useful code snippets I keep forgetting about, so blogging here for easy reference later.
Often when writing code for use with Telligent Community you'll need to get hold of the current context from the content, for example the current Group, Blog or Blog Post.
To access this, first you need to get the CurrentContext:
This provides a collection named ContextItems, which contains a Find method that you can use to get information on the current content. You can specify any rules to match against the IContextItem to fit your needs, but I tend to use ContentTypeId if just trying to find the current blog etc.
This will give you the high level info about the current blog, this can then be used to get the full blog object if required:
The same method can be used for any other content type, by using the appropriate API, e.g. PublicApi.BlogPosts, PublicApi.Groups etc.