Hands-On Lab
Adding Launchers to E-Mail and Phone Numbers
Lab version:1.0.0
Last updated:10/19/2018
Contents
Overview
Exercise 1: Add HyperlinkButtons for Phone Number and E-Mail Address
Task 1 – Beginning the Exercise
Task 2 – Configuring Constants in the Windows Phone 7 Application
Task 3 – Configuring the Reference to the SharePoint Lists.asmx Web Service
Task 4 – Implementing Code to Display the Data as a HyperlinkButton
Task 5 – Implementing Code to Send an E-Mail Message
Task 6 – Testing the Application
Summary
Overview
SharePoint Contact lists contain fields for E-Mail address and Phone number. When building interactivity into your applications it is desirable to provide users with the ability to tap an E-Mail address to send them a message or tap their phone number to call them. Windows Phone Task Launchers provide interactivity of this sort. Different launchers handle tasks such as dialing the phone, sending an E-Mail message, and sending a SMS Text message: PhoneCallTask, EmailComposeTask and SmsComposeTask respectively.
In this lab, you will create an application that reads a SharePoint Contact list. You will add controls to render the contact’s E-Mail address and Phone number. When clicked, each control will perform the appropriate action for the control;the Phone number will dial the phone and the E-Mail button will initiate the composition of an E-Mail message.
Objectives
In this hands-on lab, you will learn how to create a Windows Phone 7 application that can send e-mail and dial the phone based on SharePoint Contact list data. The Windows Phone 7 application will render the data so that users can click the phone number and e-mail address to trigger the appropriate actions.
- Learn how to create data aware hyperlink buttons
- Learn how to create an On Click event to send an Email message
- Learn how to create an On Click event to place a phone call
Prerequisites
The following is required to complete this hands-on lab:
Note: See Setting Up A SharePoint and Windows Phone 7 Development Environment Module for instructions that describe how to set up the SharePoint and Windows Phone 7 developer machine.
- Windows 7 x64 installed with all Windows Updates installed, in one of the following scenarios.
◦Installed on a physical machine
◦Installed on a bootable VHD
- SharePoint 2010 installed on the Windows 7 x64 developer machine configured with a site collection that uses Forms Based Authentication (FBA).
- Windows Phone 7 Developer Tools
◦
- Windows Phone 7 Developer Tools - January 2011 Update
◦
- Windows Phone Developer Tools Fix
◦
Note: See the Querying the List Schema for Choice Fields lab in the SharePoint and Windows Phone 7 Tips and Best Practices module for instructions that describe how to set up the SharePoint Contact list that will be used in this lab.
Exercise 1: Add HyperlinkButtons for Phone Number and E-Mail Address
In this exercise, you will change the TextBlock controls to HyperlinkButtons. You will add the methods necessary to for the On Click events to call the appropriate launcher for the button. The Windows Phone 7 application will enable the user to place a phone call or compose an e-mail message from SharePoint Contact list data.
Task 1 – Beginning the Exercise
In this task, you will open the lab solution in Visual Studio 2010.
- Make sure that you have downloaded and installed the items listed in System Requirements above prior to beginning this exercise.
- Launch Visual Studio 2010 as administrator and open the lab project by selecting File » Open » Project.
- Browse to the WP7.SharePoint.ClickAction.sln file located at %TrainingKitPath%\Labs\AddingLauncherstoEMailAndPhoneNumbers\Source\Before\ and select it.
- Click Open to open the solution.
Task 2 – ConfiguringConstants in the Windows Phone 7 Application
In this task, you will configure the constants used in the Windows Phone 7 application to work with your development environment.
- In the WP7.SharePoint.People project, in the Utilities folder, open the Constants.cs file.
- Change the value for the USER_NAME and USER_PASSWORD constants to represent a Forms Based Authentication user specific to your development environment. For this lab, the user requires read and write permissions.
- Change the value for the AUTHENTICATION_SERVICE_URL constant to the URL specific to your development environment.
The following code example demonstrates the value for a SharePoint server named fbawp7.
C#
public const string AUTHENTICATION_SERVICE_URL ="
Task 3 – Configuring the Reference to the SharePoint Lists.asmx Web Service
In this task, you willconfigure the reference to the SharePoint lists.asmx Web service. The service reference to this Web service has already been added to the project.
- In the Solution Explorer, double click the ServiceReferences.ClientConfig file to open it.
- In the Endpoint element,change the address attribute to the URL for the lists.asmx SharePoint Web service in the site where you created the Sample Tasks list.
Example:
Figure 1
Client Configuration Endpoint address
Task 4 – Implementing Code to Display the Data as a HyperlinkButton
In this task, you will edit the user interface to display the Work Phone and Email fields as Hyperlink Buttons that a user can use to send a message or place a call.
- In the WP7.SharePoint.ClickAction project, double click the ContactView.xaml file.
- Add the following code under the <!-- TODO: 10.4.1 Add the EMail HyperlinkButton -->.
XAML
<HyperlinkButton Content="{Binding DataModel.EMail}" Height="72" HorizontalAlignment="Left" x:Name="EMailLink" VerticalAlignment="Bottom" Width="450" ScrollViewer.VerticalScrollBarVisibility="Visible" Style="{StaticResource PhoneHyperlinkButtonStyle}" Click="EMailLink_Click" />
- Add the following code under the <!-- TODO: 10.4.2 Add the Phone HyperlinkButton -->.
XAML
<HyperlinkButton Content="{Binding DataModel.WorkPhone}" Height="72" HorizontalAlignment="Left" x:Name="PhoneLink" Width="450" ScrollViewer.VerticalScrollBarVisibility="Visible" Style="{StaticResource PhoneHyperlinkButtonStyle}" Click="PhoneLink_Click" />
Task 5 – ImplementingCode to Send an E-Mail Message
In this task, you will add the code required to send an email and place a phone call.
- In the WP7.SharePoint.ClickAction project, double click the ContactView.xaml.csfile.
- Add the following code under the //TODO: 10.4.3 comment to define the EmailLink_Click event handler:
C#
private void EMailLink_Click(object sender, RoutedEventArgs e)
{
//Before you leave the app, store the current item
PhoneApplicationService.Current.State["ActiveItem"] =
(viewModel.DataModel as SPContact);
//Create a new task
EmailComposeTask task = new EmailComposeTask();
//Add the current item’s EMail address
task.To = viewModel.DataModel.EMail;
//Just a little text for the message
task.Subject = "Hello from the Contact App";
//Launch the task
task.Show();
}
- Add the following code under the //TODO: 10.4.4comment to define the PhoneLink_Click event handler:
C#
private void PhoneLink_Click(object sender, RoutedEventArgs e)
{
//Create a new Phone Call task
PhoneCallTask task = new PhoneCallTask();
//Pass the current contacts phone number
task.PhoneNumber = viewModel.DataModel.WorkPhone;
//Display thier full name
task.DisplayName = viewModel.DataModel.FullName;
//Launch the task
task.Show();
}
The event handlers above use the data from the current ViewModel to populate the properties of their respective tasks before launching the task.
Task 6 – Testing the Application
In this task, you will test the Windows Phone 7 application.
- In the WP7.SharePoint.ClickAction solution, select Windows Phone 7 Emulator in the deployment location dropdown list.
- Press F5.
The Windows Phone 7 application starts in the emulator. The application will initially display the three contacts that you added to the contact list.Clicking any contact will navigate the application to the Contact View page.
Figure 2
Contacts from SharePoint
- Notice that the Work Phone number and E-Mail address are displayed as clickable links on the details page.
Figure 3
Clickable details on the details page
- Click the Phone Number field and Windows Phone 7 confirms your request to dial the number. Click don’t call.
Figure 4
Phone call confirmation
Note: On the emulator, you will not be able to dial a number or send an e-mail. Both of these activities require a physical Windows Phone 7 device. This lab is for demonstration purposes only. If you have a physicaldevice, you may deploy to it and test this functionality by changing your deployment target to Windows Phone 7 Device.
- Click the e-mail link. You will receive a “Can’t Send” error on the emulator.
Figure 5
Windows Phone E-Mail Configuration Error
- Click close to return to the application.
Summary
In this hands-on lab, you added Hyperlink Buttons to the user interface and created click event handlers for sending an e-mail and placing a phone call based on SharePoint Contact list data. This functionality takes data from SharePoint and makes it actionable on the phone, providing a better user experience for your Windows Phone 7 applications.
Page | 1