C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

OutLook Synchronize


Posted Date: 02 Jul 2007    Resource Type: Articles    Category: .NET Framework
Author: Saravana Kumar.NMember Level: Gold    
Rating: 1 out of 5Points: 10



Introduction


. First we want to add the reference of “Microsoft Outlook 11.0 Object Library” dll file add as a reference to your project. Using this we can connect to Outlook.


Creating an Object

After adding this reference ,we want to specify the namespace called “Microsoft.Office.Interop.Outlook”

1. Create an Object for the class called ApplicationClass,using this we can access all the details of the outlook

Syntax :

ApplicationClass app1 = new ApplicationClass();

2. Then create an object for Namespace to find the Namespace of the MAPI Object.

Syntax :

NameSpace outlookCNT = o.GetNamespace("MAPI");

3. Then create an object to get the detials of any default folder from the MAPI Object.

Syntax :
MAPIFolder contactfolder;
contactfolder = outlookCNT.GetDefaultFolder(OlDefaultFolders.olFolderContacts);

4. Then retrieve the data from both dataset and Contact Folder from OutLook for checking .If it match update the record or insert the record.

Syntax :


for (int i = 0; i < ds.Tables [0].Rows .Count ; i++)
{
foreach (ContactItem item in contactfolder.Items)
{
if (item.Email1Address == ds.Tables [0].DefaultView [i].Row
["EmailAddress1"] )
{

item.FirstName = ds.Tables[0].DefaultView[i].Row[3].ToString();
item.MiddleName = ds.Tables[0].DefaultView[i].Row[4].ToString();
item.Save();
flag = 1;
break;
}
else
flag = 0;
}
if (flag == 0)
{
ContactItem item1 =
(ContactItem)o.CreateItem(OlItemType.olContactItem);
item1.FirstName = ds.Tables[0].DefaultView[i].Row
[3].ToString();
item1.MiddleName = ds..Tables[0].DefaultView[i].Row
[4].ToString();
item1.Save();
}
}

First we want to put a loop upto dataset count .In that takes each record from Contact check it with dataset. If it matches it get updates or a new record get insert with Outlook Express. While inseting we must use CreateItem() method to create a new contact and then save it.

Summary

So we can synchronize the data from both Outlook to Sql server or Sql Server to OutLook using the particular refernce dll file which is very helpful to easily maintain the record.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Handling events & delegates with code example
Previous Resource: Assemblies Making easy to understand
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use