Export (0) Print
Expand All

Remove a Contact from 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.

Removing a contact from a group amounts to removing the IUccContact interface representing the contact from the collection of IUccContact objects stored in the Contacts property of the IUccGroup. Call RemoveContact on the IUccGroup interface to do this. To make the removal permanent, you must publish the group category instance as an update. The programming pattern for removing a contact is the same as renaming a group except that you are updating the Contacts property rather than the Name property.

Office Communications Server moves the removed contact to the Other Contacts group when the remove contact publishing operation succeeds.

Bb878652.note(en-us,office.12).gifNote:
Each contact to be removed from a group must be in its own publication operation. A publication object can only be used for a single publish operation.

Removing a contact from 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 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 call RemoveContact, passing the IUccContact object to be removed.
  • Set the publication operation on the publishable category to be renamed by filling the PublicationOperation property using a Unified Communications Client API enumeration value UCC_PUBLICATION_OPERATION_TYPE.UCCPOT_ADD.
  • Create a publication object by calling IUccPublicationManager 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 Office Communications Server.
  • Handle the asynchronous publish event raised with the publication response from Office Communications Server.
public void RemoveContactsFromGroup(
            IUccContact contactToRemove,
            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 cat
        IUccCategoryInstance pCat = cat.CreatePublishableCategoryInstance();

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

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

        //create publication object and register for pub 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.OnContactRemoved(
                      IUccGroup pEventSource,
                      IUccContact pEventData)
{
   ...
}
void _IUccPublicationEvent.OnPublish(
                           IUccPublication pEventSource,
                           IUccOperationProgressEvent pEventData)
{
   ...
}

Community Additions

ADD
Show:
© 2014 Microsoft