adding launchers to e-mail and phone numbersaz12722.vo.msecnd.net/.../lab.docx · web viewdifferent...

12
Hands-On Lab Adding Launchers to E-Mail and Phone Numbers Lab version: 1.0.0 Last updated: 9/2/2022 Page | 1

Upload: others

Post on 05-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

Hands-On LabAdding Launchers to E-Mail and Phone Numbers

Lab version: 1.0.0

Last updated: 5/21/2023

Page | 1

Page 2: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

CONTENTS

OVERVIEW................................................................................................................................................. 3

EXERCISE 1: ADD HYPERLINKBUTTONS FOR PHONE NUMBER AND E-MAIL ADDRESS...............4Task 1 – Beginning the Exercise...........................................................................................................4

Task 2 – Configuring Constants in the Windows Phone 7 Application.................................................4

Task 3 – Configuring the Reference to the SharePoint Lists.asmx Web Service..................................5

Task 4 – Implementing Code to Display the Data as a HyperlinkButton..............................................5

Task 5 – Implementing Code to Send an E-Mail Message....................................................................6

Task 6 – Testing the Application..........................................................................................................7

SUMMARY................................................................................................................................................ 11

Page | 2

Page 3: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

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).

Page | 3

Page 4: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

Windows Phone 7 Developer Tools

◦ http://download.microsoft.com/download/1/7/7/177D6AF8-17FA-40E7-AB53- 00B7CED31729/vm_web.exe

Windows Phone 7 Developer Tools - January 2011 Update

◦ http://download.microsoft.com/download/6/D/6/6D66958D-891B-4C0E-BC32- 2DFC41917B11/WindowsPhoneDeveloperResources_en-US_Patch1.msp

Windows Phone Developer Tools Fix

◦ http://download.microsoft.com/download/6/D/6/6D66958D-891B-4C0E-BC32- 2DFC41917B11/VS10-KB2486994-x86.exe

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.

1. Make sure that you have downloaded and installed the items listed in System Requirements above prior to beginning this exercise.

2. Launch Visual Studio 2010 as administrator and open the lab project by selecting File » Open » Project.

a. Browse to the WP7.SharePoint.ClickAction.sln file located at %TrainingKitPath%\Labs\AddingLauncherstoEMailAndPhoneNumbers\Source\Before\ and select it.

b. Click Open to open the solution.

Task 2 – Configuring Constants in the Windows Phone 7 Application

Page | 4

Page 5: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

In this task, you will configure the constants used in the Windows Phone 7 application to work with your development environment.

1. In the WP7.SharePoint.People project, in the Utilities folder, open the Constants.cs file.

2. 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.

3. 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 = "http://fbawp7/_vti_bin/authentication.asmx";

Task 3 – Configuring the Reference to the SharePoint Lists.asmx Web Service

In this task, you will configure the reference to the SharePoint lists.asmx Web service. The service reference to this Web service has already been added to the project.

1. In the Solution Explorer, double click the ServiceReferences.ClientConfig file to open it.

2. 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: http://fbawp7/_vti_bin/lists.asmx

Figure 1Client 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.

1. In the WP7.SharePoint.ClickAction project, double click the ContactView.xaml file.

2. Add the following code under the <!-- TODO: 10.4.1 Add the EMail HyperlinkButton -->.

XAML

Page | 5

Page 6: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

<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" />

3. 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 – Implementing Code to Send an E-Mail Message

In this task, you will add the code required to send an email and place a phone call.

1. In the WP7.SharePoint.ClickAction project, double click the ContactView.xaml.cs file.

2. 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();}

3. Add the following code under the //TODO: 10.4.4 comment to define the PhoneLink_Click event handler:

C#

Page | 6

Page 7: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

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.

1. In the WP7.SharePoint.ClickAction solution, select Windows Phone 7 Emulator in the deployment location dropdown list.

2. 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.

Page | 7

Page 8: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

Figure 2Contacts from SharePoint

3. Notice that the Work Phone number and E-Mail address are displayed as clickable links on the details page.

Page | 8

Page 9: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

Figure 3Clickable details on the details page

4. Click the Phone Number field and Windows Phone 7 confirms your request to dial the number. Click don’t call.

Page | 9

Page 10: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

Figure 4Phone 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 physical device, you may deploy to it and test this functionality by changing your deployment target to Windows Phone 7 Device.

5. Click the e-mail link. You will receive a “Can’t Send” error on the emulator.

Page | 10

Page 11: Adding Launchers to E-Mail and Phone Numbersaz12722.vo.msecnd.net/.../Lab.docx · Web viewDifferent launchers handle tasks such as dialing the phone, sending an E-Mail message, and

Figure 5Windows Phone E-Mail Configuration Error

6. 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 | 11