Have any of you used categories to categorized the content of the site? I guess not. When the category structure contains more than 20 element it gets almost impossible to navigate and use the category tree. My guess is that most of you uses the categories to label certain content so it can be shown on the front page, news item and so on.
My pet project at the moment is to try to use the category function in EPiServer to do something more than just labeling. As always I started out big and are thinking about using Calais to automatically categorizes content, but as a spin off I made this property
Property SelectOrAddCategory
If you have an event page and in that page you want the editors to store Location, and Person(s) that are going to speak at the event I guess most of you would have solved this with two text properties. The only drawback with this approach is that both the location and persons names are going to be spelt different, and with different caps. Not a problem so far, but if you want to show all events from one location you have to make some more logic to make that work.
Category could be used to archive this, but as implemented in EPiServer at the movement its a hassle. :)
I have made an property that will make a category in the category tree and add all added values as sub categories. These categories will be tagged as not visible so they want show up in the categories tree. The property have an text box where you can start typing in a location. There is a auto completion area that will show other locations that starts with what you are typing.That will ensure (help) that the editors don't make two or more different variants of Oslo.
If the desired location is not in the list, it will be created.

The property itself is pretty straight forward. The only tricky part is to save the connection from the current page to the selected categories. If you in ApplayEditChange try to:
SetValue(result, this.Properties["PageCategory"]);
it will only work if the property is displayed after the Category property. I therefore had to make attach me to the Saving event and to change the PageCategory there.
public static void Start()
{
EPiServer.DataFactory.Instance.SavingPage += new EPiServer.PageEventHandler(Instance_SavingPage);
}
static void Instance_SavingPage(object sender, EPiServer.PageEventArgs e)
{
CategoryList before = e.Page.Category;
CategoryList newSave = new CategoryList();
EPiServer.DataAbstraction.Category cat = null;
foreach (PropertyData prop in e.Page.Property)
if (prop is PropertySelectOrAddCategory)
{
foreach (int catID in before)
{
cat = EPiServer.DataAbstraction.Category.Find(catID);
if (cat.Parent == null || cat.Parent.Name != prop.Name)
newSave.Add(catID);
}
foreach (int catID in (prop as PropertySelectOrAddCategory).Category)
newSave.Add(catID);
}
e.Page.Property["PageCategory"].Value = newSave;
}
Download
the whole code is available as one file with 3 classes.