This topic demonstrates how to publish the availability and personal note of the local user contact. This process involves defining an array of contact information types and a Dictionary< PublishableContactInformationType , object > that holds the contact information to be published. Publishing a set of contact information items raises the ContactInformationChanged event on the publishing contact. If the publishing contact is the local user then the event is raised both locally and for remote users who have subscribed to the local contact.

Publishing Contact Information

The following figure illustrates the classes, methods, and events used in the process of publishing contact information.

Publish Presence Information

  1. Get the LyncClient instance. Verify that the client is signed in to the server. For information about signing in to Microsoft Lync Server 2010, see Walkthrough: Sign In to Lync .

  2. Create a Dictionary< PublishableContactInformationType , object > of contact information types and the corresponding values to be updated. The Dictionary you declare and instantiate is passed into BeginPublishContactInformation .

  3. Add a ContactInformationType and the corresponding publishable value to the dictionary you created previously.

  4. Read the Self property to get an instance of Self .

  5. Optional: Declare and instantiate a state object such as a string , and fill it with appropriate state information. The callback method you provide should access this state information to provide a context for the operation.

  6. Call BeginPublishContactInformation , passing the dictionary, the callback method (or null), and the state object.


The following examples publish the presence information typically published in a custom application.

Publish a Personal Note and Current Availability

The following example method publishes a new personal note for the local user.

Tip Tip

In the example, a callback method included as a parameter in the PublishPresenceItemsmethod call. You should pass a nullvalue in the callback parameter position if you are not interested in catching the result of the publication.

C#  Copy imageCopy Code
		/// <summary>
		/// Publishes an update to a personal note
		/// </summary>
		/// <param name="newNote">string. The new personal
note text.</param>
		public void PublishPersonalNoteAndFreeAvailability(string
			//Each element of this array must contain a valid
enumeration. If null array elements 
			//are passed, an ArgumentException is raised.
object> publishData = new
Dictionary<PublishableContactInformationType, object>();

			//Helper method is found in the next example.
			SendPublishRequest(publishData, "Personal Note and

The following example begins the asynchronous publication process.

C#  Copy imageCopy Code
		/// <summary>
		/// Sends a publication request and handles any exceptions
		/// </summary>
		/// <param name="publishData">Dictionary. Information
to be published.</param>
		/// <param name="PublishId">string. Unique
publication identifier.</param>
		private void SendPublishRequest(
object> publishData,
			string PublishId)
			object publishState = (object)PublishId;
			object[] _PublishAsyncState = { _LyncClient.Self,
publishState };
			catch (COMException ce)
				MessageBox.Show("publish COM exception: " +
			catch (ArgumentException ae)
				MessageBox.Show("publish Argument exception: " +

The following example is the callback method passed into BeginPublishContactInformationin the previous example.

C#  Copy imageCopy Code
		/// <summary>
		/// callback method called by
		/// </summary>
		/// <param name="ar">IAsyncResult. Asynchronous
result state.</param>
		private void PublicationCallback(IAsyncResult ar)
			if (ar.IsCompleted)
				object[] _asyncState = (object[])ar.AsyncState;

The following example handles the ContactInformationChanged event that is raised when the current contact information state has changed. The example uses a message box to notify a user that presence has been updated and then removes the registration for Contact contact information update events.

C#  Copy imageCopy Code
		/// <summary>
		/// Handles event raised when the presence of a contact has
been updated
		/// </summary>
		/// <param name="source">Contact. Contact instance
whose presence is updated</param>
		/// <param name="data">PresenceItemsChangedEventArgs.
Collection of presence item types whose values have been
		void Contact_ContactInformationChanged(object sender,
ContactInformationChangedEventArgs e)
			if (((Contact)source) == _LyncClient.Self.Contact)
				System.Text.StringBuilder sb = new
				sb.Append("Changed types: " +
				foreach (ContactInformationType
changedInformationType in e.ChangedContactInformation)
					sb.Append(changedInformationType.ToString() +
				MessageBox.Show("Self publish succeeded: " +