This documentation is archived and is not being maintained.

Create a Contact Group

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

A contact group is an instance of the groups category. To persist a contact group on Office Communications Server between logon sessions, the new contact group category instance has to be published to the server.

Creating a contact group involves the following steps:

  • Create a publication manager object by casting an IUccEndpoint object into a IUccPublicationManager object. The publication manager is responsible for creating a publishable category instance object and publication object.
  • Create a publishable category instance representing the group to be added. In this example, the added group has no expiry date. For this reason, the enumeration value UCC_CATEGORY_INSTANCE_EXPIRATION_TYPE.UCCCIET_STATIC is used.
  • Set the publication operation on the created publishable category by filling the PublicationOperation property using a UCCP enumeration value UCC_PUBLICATION_OPERATION_TYPE.UCCPOT_ADD.
  • Cast the IUccCategoryInstance object to the IUccGroup interface.
  • Set the group properties as required. Note that the PrivateId property cannot be set for user-defined groups. This property is only available for distribution groups.
  • Create a publication object by calling CreatePublication and casting the returned value to the IUccPublication interface.
  • Register for publication events to catch the asynchronous response to this publication request.
  • Add the IUccCategory instance created earlier to the publication with a call into AddPublishableCategoryInstance. Each publication object can contain one group. To publish multiple groups, you must create a publication object for each group.
  • Publish the new group by calling the Publish method on the publication object. In this example, the optional Operation Context is not supplied with the request.

public void AddGroup(string groupName)
{
   try
   {
      IUccPublicationManager pubMgr = endpoint as IUccPublicationManager;
   //Create a publishable category instance representing the group to be added
      IUccCategoryInstance cat = pubMgr.CreatePublishableCategoryInstance("groups", 0, 0, UCC_CATEGORY_INSTANCE_EXPIRATION_TYPE.UCCCIET_STATIC, 0);

      //Set publication operation type for this category
      cat.PublicationOperation = UCC_PUBLICATION_OPERATION_TYPE.UCCPOT_ADD;

      //Cast the category to IUccContact to set the URI of the contact to be added
      IUccGroup g = cat as IUccGroup;
      g.Name = groupName;
      g.GroupType = UCC_GROUP_TYPE.UCCGT_USER_DEFINED_GROUP;
      IUccPublication pub = pubMgr.CreatePublication() as IUccPublication;
      UCC_Advise<_IUccPublicationEvent>(pub, this);
      pub.AddPublishableCategoryInstance(cat);
      pub.Publish(null);
   }
   catch (COMException ex)
   {
      Console.WriteLine(ex.ToString());
   }
}
Show: