Click here to Skip to main content
15,867,594 members
Articles / Mobile Apps / Windows Mobile

Sending SMS on Pocket PC

Rate me:
Please Sign up or sign in to vote.
2.86/5 (6 votes)
1 Jun 2007CPOL 42.4K   762   38   8
Easy way to send a message using C#.

Introduction

This is a sample for using Pocket PC to send SMS.

Background

I tried to solve a problem that uses Pocket PC to send SMS in my projects. I downloaded Microsoft SDK and found this sample. Now I hope that it can be useful for other programmers.

Using the Code

C#
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.Telephony;
private OutlookSession outlookSession;

public ContactSelector()
{
    this.outlookSession = new OutlookSession();          
}

        private void NewButton_Click(object sender, System.EventArgs e)
        {                   
            // Add contact to the contacts folder. 
            // Just do an update once the information has been entered.
            contactToSelect = new Contact();                        
            this.outlookSession.Contacts.Items.Add(contactToSelect);
            
            // Edit the newly created contact.
            ContactEditor contactDialog = new ContactEditor();
            contactDialog.Edit(ref contactToSelect);    
         
            this.InitializeListBox();
        }
        /// <summary>
        /// This event handler gets called when the "Edit" button is pressed.
        /// It sets contactToSelect as the contact selected on the ListBox.         
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Event arguments.</param>
        private void EditButton_Click(object sender, System.EventArgs e)
        {            
            if (this.listBox1.SelectedItem != null)
            {
                contactToSelect = (Contact)this.listBox1.SelectedItem;
            } 
            
            ContactEditor contactDialog = new ContactEditor();
            contactDialog.Edit(ref contactToSelect);
        }
        /// <summary>
        /// This will send an SMS Message.
        /// </summary>
        /// <param name="sender">Sender of the message</param>
        /// <param name="e">Event arguments.</param>
        private void SendSmsButton_Click(object sender, System.EventArgs e)
        {
           try
           {
                contactToSelect = (Contact)this.listBox1.SelectedItem;
                if (outlookSession.SmsAccount == null)
                    throw new ArgumentException("The account is not initialized");
                MessageBox.Show("Transport:"+outlookSession.SmsAccount.Name);
                SmsMessage s = new SmsMessage(contactToSelect.MobileTelephoneNumber, 
                    this.smsText.Text);
                s.Body = this.smsText.Text; //Create some input.
                s.Send();
           }
           catch (NullReferenceException except)
           {
                MessageBox.Show(except.ToString());
           }
        }
        
        /// <summary>
        /// Call BusinessTelephoneNumber
        /// </summary>
        /// <param name="sender">Sender of event.</param>
        /// <param name="e">Event Arguments</param>
        private void CallWorkButton_Click(object sender, System.EventArgs e)
        {
           contactToSelect = (Contact)this.listBox1.SelectedItem;
            Phone p = new Phone();
            p.Talk(contactToSelect.BusinessTelephoneNumber);
            
        }

License

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


Written By
Software Developer (Senior) www.treaple.com
China China
Treaple offshore outsourcing software services providing mobile(Pocket pc,smartphone and wince.net) software,mobile GIS(Mobile map),Desktop GIS(Desktop map), GPS,GSM Locating Services,Voip,Multimedia(Audio,Video) and web design offshore outsourcing software development services.We have developed lots of projects on Microsoft Poccket pc 5.0/6.0,smartphone 5.0/6.0 and Microsoft windows and got strong background in Microsoft MapPoint, ESRI ArcGIS, Map info,Google map etc
Our website below: http://www.szwyqz.com

Comments and Discussions

 
Generalnull inner exception Pin
Syed Kawsar13-Dec-10 4:57
Syed Kawsar13-Dec-10 4:57 
Generaldoubt Pin
sujamca23-Mar-09 23:38
sujamca23-Mar-09 23:38 
JokeAbout your Background Pin
Du Sijun3-Jun-07 22:05
Du Sijun3-Jun-07 22:05 
GeneralRe: About your Background Pin
John.Jiang3-Jun-07 22:20
John.Jiang3-Jun-07 22:20 
GeneralPlease revise this article Pin
Niteman30-May-07 0:33
Niteman30-May-07 0:33 
GeneralRe: Please revise this article Pin
John.Jiang1-Jun-07 7:01
John.Jiang1-Jun-07 7:01 
AnswerRe: Please revise this article Pin
Niteman5-Jun-07 23:53
Niteman5-Jun-07 23:53 

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.