I'm writing a library, making use of the C# K2 APIs, which determines which smartobjects (SMOs) and methods are in an inconsistent state. I've been able to do this sucessfully but I cannot find a way to get the category a SMO is associated with.
In the smart object tester you can see the category a SMO is associated with, as it appears under a folder icon. I'd like to get the same information programatically.
I was hoping to find the category information inside an instance of the SmartObjectInfo class (e.g. within the Metadata property) but it does not appear to be there.
I also had a brief look at the SourceCode.Categories.Client.dll library, and was hoping to find a method where I could determine the category of a SMO, but I couldn't find anything.
Can anyone let me know how I can use the K2 API to get at the category info for a SMO?
Solved! Go to Solution.
Below is a code snippet i wrote to get the full category path of any object. To get the SmartObject category path you will need to pass in the SMO Guid and the object type as "SmartObject". You will need to reference SourceCode.Categories.Client.dll and use the CategoryServer object.
You will need to create a connection string like: "Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=localhost;Port=5555;WindowsDomain=[domain name];SecurityLabelName=K2"
public string ObjectCategoryPath(string objectGuid, string objectType)
CategoryServer catServer = new CategoryServer();
BaseAPIConnection conn = catServer.CreateConnection();
int cats = catServer.GetCategoriesByDataId(objectGuid, objectType);
if (cats.Length != 0)
StringBuilder path = new StringBuilder();
CategoryManager catManager = catServer.GetCategoryManager(1, false);
Category cat = catManager.Categories.GetCategoryById(cats);
Category parentCat = cat.ParentCategory;
cat = parentCat;
// remove first forward slash