CS Nuglet: Check on DuplicateName on Programmatic Post Creation

This is more for the guys who hang out at the Community Server Developer Cafe, but if you’re entering post objects programmatically in Community Server it’s a good idea to handle the PostResults.DuplicationName post.Add() result. 

The core of my Community Server-based Job Management Application is the JobPost object, which is an extension of the WeblogPost object.  The name of the job is the Post.Name, the equivalent of a blog post title.  In my application I import job data in a background task from various external sources and turn it into JobPosts.  It’s a beautiful thing, really.  Yet I was noticing recently that an imported job record was not being converted into a JobPost object.  It dawned on me to check for the existence of the job name in the system that was assigned to an earlier job number.  With the discovery of the duplicate job name in the post name field I began handling the PostResults.DuplicationName result as you can see below.  Beneath the code is an example of the Eventlog entry I’m writing when a duplicate is found.  You can, of course, auto-rename the post based on some algorithm, but writing to the event log is sufficient for my app’s needs.  



Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.