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