C # add, delete, and query outlook contacts

Source: Internet
Author: User
Original article: C # add, delete, and query outlook contacts [go]

Note: define variables

Outlook. Application myolapp = newoutlook. applicationclass ();
Outlook. namespace mynamespace;
Outlook. mapifolder myfolder;

1. Add a contact

Outlook. contactitem additem = (outlook. contactitem) myolapp. createitem (outlook. olitemtype. olcontactitem );
Additem. firstname = "Jingjing ";
Additem. lastname = "Li ";
Additem. email1address = "[email protected]";
Additem. Save ();

2. delete a contact

Outlook. contactitem contact =
   This. myolapp. getnamespace ("mapi ").
Getdefaultfolder (outlook. oldefaultfolders. olfoldercontacts ).
Items.
Find (
String. Format ("[lastname] = '{0}' and [firstname] = '{1 }'",
Lastname, firstname ))
As outlook. contactitem;

If (contact! = NULL)
{
   Contact. Delete ();
}

3. query contacts

 Mynamespace = myolapp. getnamespace ("mapi"); // obtain the mapi session
           Myfolder = mynamespace. getdefaultfolder (outlook. oldefaultfolders. olfoldercontacts); // obtain the default mailbox Information

           Int imailcount = myfolder. Items. count;
           If (imailcount> 0)
           {
               For (int K = 1; k <= imailcount; k ++)
               {
                   Outlook. contactitem item = (outlook. contactitem) myfolder. items [k];
                   If (! Columnmobiles. Contains (item. mobiletelephonenumber) // Add a contact that does not exist in the Database
                   {
                       String lastname = item. lastname; // surname
                       String firstname = item. firstname; // name
                       String fullname = item. fullname; // full name
                       // String sex = item. Gender. tostring (); // gender
                       String email = item. email1address + "," + item. email2address + "," + item. email3address; // email
                       String job = item. jobtitle; // Title
                       String Department = item. Department; // Department
                       String Company = item. companyName; // Unit
                       String mobile = item. mobiletelephonenumber; // mobile phone
                       String Birthday = "";
                       If (! Item. Birthday. tostring (). Equals ("4501-1-1 0:00:00 "))
                           Birthday = item. Birthday. tostring (); // birthday                  

                       // Item. pagernumber // Pager
                       String corfax = item. businessfaxnumber; // business Fax
                       String homepage = item. businesshomepage; // webpage address
                       String corphone = item. businesstelephonenumber; // business phone number
                       String cornation = item. businessaddresscountry; // country
                       String corprovince = item. businessaddressstate; // Province
                       String corarea = item. businessaddresscity; // City
                       String coraddress = item. businessaddressstreet; // address
                       String corpostcode = item. businessaddresspostalcodE; // zip code


                       String nation = item. homeaddresscountry; // residential country
                       String province = item. homeaddressstate; // residential Province
                       String area = item. homeaddresscity; // residential city
                       String postcode = item. homeaddresspostalcode; // residential zip code
                       String address = item. homeaddressstreet; // residential address
                       String handset = item. hometelephonenumber; // residential phone number
                       String Fax = item. homefaxnumber; // residential Fax


                       // Item. businessaddress // combination address (Anping County, Hengshui City, Hebei Province)
                       // Item. formdescription. Icon // The image is not clear
                       // Item. haspicture // whether an image exists
                       // Item. homeaddress // residential address
                       // Item. primarytelephonenumber // main phone number
                       // Item. managername // manager name

                       

                       // Execute add
                       Bool result = associatemanager. addassociate (Associate );

                       If (k = imailcount)
                       {
                           MessageBox. Show ("data imported successfully! "," System prompt ", messageboxbuttons. OK, messageboxicon. information );
                           This. Close (); // close the window
                       }
                   }
               }
           }
           Else
               MessageBox. Show ("sorry, no imported data! "," System prompt ", messageboxbuttons. OK, messageboxicon. information );


From: http://blog.csdn.net/as7616263/archive/2010/05/25/5623222.aspx

C # add, delete, and query outlook contacts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.