Click here to Skip to main content
13,458,533 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 28 Mar 2012

How to Save Contact in WP7 using the SaveContactTask?

, 28 Mar 2012
Rate this:
Please Sign up or sign in to vote.
How to save Contact in WP7 using the SaveContactTask

Windows Phone 7 SDK exposes API to provide user option to save any contact to the Contact list. In your app, you may want to include contact saving option. This small post will help you to understand the API and after that, you will be able to use it in any of your applications.

The SDK has a sealed class called SaveContactTask, which you can use to implement this feature. Continue reading to know more about the class and implementation steps.

Know About the API

SaveContactTask is a sealed class present in the Microsoft.Phone.Tasks namespace which derives from ChooserBase of type SaveContactResult. The SaveContactTask class provides a bunch of properties, which you can set to auto fill the contact information. The class has only one method called Show() which launches the New Contact screen.

Here is the meta data of the SaveContactTask class, where you can see all the exposed properties that you can use:

namespace Microsoft.Phone.Tasks
    public sealed class SaveContactTask : ChooserBase<savecontactresult>
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string MiddleName { get; set; }
        public string Nickname { get; set; }
        public string Suffix { get; set; }
        public string Company { get; set; }
        public string Title { get; set; }
        public string MobilePhone { get; set; }
        public string HomePhone { get; set; }
        public string WorkPhone { get; set; }
        public string PersonalEmail { get; set; }
        public string WorkEmail { get; set; }
        public string OtherEmail { get; set; }
        public string HomeAddressStreet { get; set; }
        public string HomeAddressCity { get; set; }
        public string HomeAddressState { get; set; }
        public string HomeAddressZipCode { get; set; }
        public string HomeAddressCountry { get; set; }
        public string WorkAddressStreet { get; set; }
        public string WorkAddressCity { get; set; }
        public string WorkAddressState { get; set; }
        public string WorkAddressZipCode { get; set; }
        public string WorkAddressCountry { get; set; }
        public string Website { get; set; }
        public string Notes { get; set; }
        public string JobTitle { get; set; }

        public override void Show();

You can use the Completed event to know whether the saving operation has been successfully ended or not.

Implementation Steps

To implement the contact saving operation, create the instance of the class and set the optional properties that you want to auto fill when user launches the save contact screen from your application. Register for the completed event to know whether the saving operation has been successful.

// Create the instance of the SaveContactTask
var saveContactTask = new SaveContactTask();

// Set the optional properties that you want to auto populate with
saveContactTask.Title = "Mr.";
saveContactTask.FirstName = "Kunal";
saveContactTask.LastName = "Chowdhury";
saveContactTask.MobilePhone = "+91-8888779569";
saveContactTask.HomePhone = "(018) 741236555";
saveContactTask.WorkPhone = "(018) 1999984562";
saveContactTask.Website = "";

// Register the Save Completed event
saveContactTask.Completed += SaveContactTask_Completed;

// Call the Show method to open the Contact Screen

Finally, call the Show() method to launch the New contact saving screen in your Windows Phone 7 device. Based on the SaveContactResult in the Completed event implementation, take necessary actions as demonstrated below:

void SaveContactTask_Completed(object sender, SaveContactResult e)
    switch (e.TaskResult)
        case TaskResult.OK:
            // Contact Saved

        case TaskResult.Cancel:
            // Contact Saving Operation Cancelled


That’s all about the coding part. When you launch it, you will see that the new phone contact screen has been auto populated with the values that you set from the code. If you want to add more details, you will be able to do that from that screen as shown below:

Image 1: How to Save Contact in WP7 using the SaveContactTask? Image 2: How to Save Contact in WP7 using the SaveContactTask? Image 3: How to Save Contact in WP7 using the SaveContactTask?

Finally, the user needs to Save the contact by clicking the save button present in the App Bar of the screen, else the contact will not getting saved automatically. Hope this small tip was helpful for you to understand the API and the implementation process.


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

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180323.1 | Last Updated 28 Mar 2012
Article Copyright 2012 by Kunal Chowdhury «IN»
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid