Click here to Skip to main content
13,453,986 members (52,010 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 15 Apr 2012

How to Retrieve a Phone Number from Contacts in WP7 using the PhoneNumberChooserTask?

, 15 Apr 2012
Rate this:
Please Sign up or sign in to vote.
How can you programmatically retrieve a phone number from an existing contact list?

In the last blog post, we learnt “How to Call a Number in WP7 using the PhoneCallTask?” We also learnt, “How to Save Phone Number in WP7 using the SavePhoneNumberTask?” So, how can you programmatically retrieve a phone number from an existing contact list?

This post will help you to understand it. After reading this post, you will be able to programmatically retrieve the phone number in your application (this requires user’s interaction) using the PhoneNumberChooserTask. Don’t forget to read the complete post as this will help you to know about the internal implementation of the SDK API too.

Know About the API

PhoneNumberChooserTask” is a sealed class present in the “Microsoft.Phone.Tasks” namespace. It inherits “ChooseBase” of type “PhoneNumberResult” which returns the selected phone number and display name. PhoneNumberChooserTask has a method called Show() which brings the contact chooser UI in the screen.

Here is the meta data of the PhoneNumberChooserTask:

namespace Microsoft.Phone.Tasks
    public sealed class PhoneNumberChooserTask : ChooserBase<PhoneNumberResult>
        public override void Show();

Today I decompiled the SDK library for PhoneNumberChooserTask class and learnt a lot about the actual implementation of the API. You will find it really useful.

Here is the actual API implementation of the class:

namespace Microsoft.Phone.Tasks
  public sealed class PhoneNumberChooserTask : ChooserBase<PhoneNumberResult>
    private const int StaticFilterHasPhone = 4;
    private const string AppUri = 


    public override void Show()
      if (!ChooserHelper.NavigationInProgressGuard((Action) (() => this.Show())))
      byte[] buffer = ChooserHelper.Serialize(this.BuildParameterPropertyBag());
      Uri appUri = new Uri(this.BuildUri(), UriKind.Absolute);
      ChooserHelper.Invoke(appUri, buffer, (IChooser) this._genericChooser);

    internal override string BuildUri()
      return "app://5B04B775-356B-4AA0-AAF8-6491FFEA5615/ChoosePropertyOfExistingPerson";

    internal override ParameterPropertyBag BuildParameterPropertyBag()
      ParameterPropertyBag parameterPropertyBag = new ParameterPropertyBag();
      parameterPropertyBag.CreateProperty("RestrictionType").Int32Value = 4;
      return parameterPropertyBag;

    internal override void OnInvokeReturned(byte[] outputBuffer, Delegate fireThisHandlerOnly)
      bool flag = false;
      if (outputBuffer.Length > 0)
        ParameterPropertyBag parameterPropertyBag = new ParameterPropertyBag(
                                                        (uint) outputBuffer.Length);
        ParameterProperty property1 = parameterPropertyBag.GetProperty("PickerPropertyValue");
        if (property1.ValueType == ParameterPropertyValueType.ValueType_String && !


          flag = true;
          PhoneNumberResult e = new PhoneNumberResult(TaskResult.OK);
          e.PhoneNumber = property1.StringValue;
          ParameterProperty property2 = parameterPropertyBag.GetProperty("OutDisplayName");
          if (property2.ValueType == ParameterPropertyValueType.ValueType_String)
            e.DisplayName = property2.StringValue;
          this.FireCompleted((object) this, e, fireThisHandlerOnly);
      if (flag)
      this.FireCompleted((object) this, new PhoneNumberResult(TaskResult.Cancel), 



I hope that the above decompiled version of the class was very helpful for you to understand the actual implementation.

Implementation Steps

Let’s implement a sample code and discuss how it works using a simple application. First of all, you have to create an instance of the class PhoneNumberChooserTask and register for the completed event before calling the Show() method. Here is the code snippet for your reference:

var phoneNumberChooserTask = new PhoneNumberChooserTask();
phoneNumberChooserTask.Completed += PhoneNumberChooserTaskCompleted;

In the completed event implementation, extract the PhoneNumberResult and retrieve the DisplayName and PhoneNumber from it. You can store it or pass it to PhoneCallTask to place a call like the below code snippet:

void PhoneNumberChooserTaskCompleted(object sender, PhoneNumberResult e)
    var phoneCallTask = new PhoneCallTask 
                                DisplayName = e.DisplayName, 
                                PhoneNumber = e.PhoneNumber 

Not only that, you can do any operation that your application wants after retrieving this information. Let’s see how it works in the Windows Phone 7 device.

Once you call the Show() method, the first screen will appear in the device asking user to chose the contact and in the completed event once you get the information, it will ask you to place a call (as per our implementation) and then the 3rd screen shows the call to that contact as below:

Screenshot 1 : How to Retrieve Phone Number from Contacts in WP7 using the PhoneNumberChooserTask?     Screenshot 2 : How to Retrieve Phone Number from Contacts in WP7 using the PhoneNumberChooserTask?     Screenshot 3 : How to Retrieve Phone Number from Contacts in WP7 using the PhoneNumberChooserTask?

I hope that, this post was helpful to you to understand the basic and implementation of the API. If you like these posts, don’t forget to share with your friends, colleagues or others whom you believe that this post will be useful. Don’t forget to share your feedback as it will help me to improve my future posts and also encourage me to deliver more for the benefit of you.

Stay tuned to my blog, Twitter or Facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

Reference: You may like to follow me on twitter @kunal2383 or may like the Facebook page of my blog


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Kunal Chowdhury «IN»
Software Developer (Senior)
India India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik Developer Expert, Nokia Developer Champion, Windows 10 Champion, Microsoft Rockstar, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows Store (WinRT) app development. He posts his findings, articles, tutorials in his technical blog and CodeProject.

Book authored:

Connect with me on:

My CodeProject Awards/Prizes:

You may also be interested in...


Comments and Discussions

SuggestionFormatting of the code blocks Pin
Mika Wendelius14-Apr-12 9:00
mvpMika Wendelius14-Apr-12 9:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180321.1 | Last Updated 15 Apr 2012
Article Copyright 2012 by Kunal Chowdhury «IN»
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid