Share via


Add a Contact to 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.

Adding a contact to a group amounts to adding the IUccContact interface representing the contact to the collection of IUccContact objects stored in the Contacts property of the IUccGroup. Call AddContact to add the contact to the collection. To make the addition permanent, you must publish the group category instance as an update. The programming pattern for adding a contact is the same as for renaming a group except that you are updating the Contacts property rather than the Name property.

Programming Pattern

Adding a contact to a group involves the following steps:

  • Create a publication manager object by casting an IUccEndpoint object into an IUccPublicationManager object. The publication manager is responsible for creating a publishable category instance object and publication object. You create the publication manager once for the endpoint and use it for each publishing operation that you perform.
  • Get a category instance representing the group to be added by casting the IUccGroup interface into an IUccCategoryInstance.
  • Create a publishable category instance by calling CreatePublishableCategoryInstance.
  • Cast the publishable category to the IUccGroup interface to gain access to the property being updated and set the Contacts property value by calling AddContact.
  • Set the publication operation on the publishable category to be renamed by filling the PublicationOperation property using a UCCP enumeration value UCC_PUBLICATION_OPERATION_TYPE.UCCPOT_ADD.
  • 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 IUccCategoryInstance created earlier to the publication with a call into AddPublishableCategoryInstance.
  • Publish the updated group by calling the Publish method on the publication object. In this example, the optional Operation Context is not supplied with the request.
  • Handle the asynchronous group event raised with the publication response from the Office Communicator server.
  • Handle the asynchronous publish event raised with the publication response from the Office Communicator server.
public void AddContactsToGroup(
            IUccContact contactToAdd,
            IUccGroup pGroup)
{
    try
    {
        IUccPublicationManager pubMgr = endpoint as IUccPublicationManager;
        // QI the IUccGroup to its IUccCategoryInstance.
        IUccCategoryInstance cat = pGroup as IUccCategoryInstance;

        // Create new publishable category based on the original category.
        IUccCategoryInstance pCat = cat.CreatePublishableCategoryInstance();

        // QI the publishable category to IUccGroup to gain access
        // to the group properties.
        IUccGroup iGroup = pCat as IUccGroup;
        iGroup.AddContact(contactToAdd);

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

        // Create publication object and register for publication events.
        IUccPublication pub = pubMgr.CreatePublication() as IUccPublication;
        UCC_Advise<_IUccPublicationEvent>(pub, this);

        // Add the publishable category instance created before
        // to publish it.
        pub.AddPublishableCategoryInstance(pCat);
        pub.Publish(null);
    }
    catch (COMException ex)
    {
        Utilities.ReportError(ex.ToString());
    }
}
void _IUccGroupEvents.OnContactAdded(
                      IUccGroup pEventSource,
                      IUccContact pEventData)
{
   ...
}
void _IUccPublicationEvent.OnPublish(
                           IUccPublication pEventSource,
                           IUccOperationProgressEvent pEventData)
{
   ...
}

See Also

Concepts

Create a Contact Group
Move a Contact to Another Contact Group
Remove a Contact from a Contact Group
Rename a Contact Group
Remove a Contact Group