Tuesday, June 2, 2009

Imports Data From OutLook in Javascript and save in db in post method

function ImportFromOutLook()
{
try
{
if((window.ActiveXObject))
{
var Const_olFolderContacts = 10;
var objApp = new ActiveXObject('Outlook.Application');
var objNS = objApp.GetNamespace('MAPI');
var colContacts = objNS.GetDefaultFolder(Const_olFolderContacts).Items
if(colContacts.count==0)
alert('No Contacts in your Outlook');
for( var i=1; i<=colContacts.count;i++)
{
var v = colContacts.item(i);
var xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST", "../Popup/Ajax.aspx", true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Connection", "close");
var data="FullName="+encodeURIComponent(v["FullName"])+
"&HomeAddressStreet="+encodeURIComponent(v["HomeAddressStreet"])+
"&HomeAddressCity="+encodeURIComponent(v["HomeAddressCity"])+
"&HomeAddressPostalCode="+encodeURIComponent(v["HomeAddressPostalCode"])+
"&HomeAddressState="+encodeURIComponent(v["HomeAddressState"])+
"&HomeAddressCountry="+encodeURIComponent(v["HomeAddressCountry"])+
"&HomeTelephoneNumber="+encodeURIComponent(v["HomeTelephoneNumber"])+
"&HomeFaxNumber="+encodeURIComponent(v["HomeFaxNumber"])+
"&Email1Address="+encodeURIComponent(v["Email1Address"])+
"&BusinessAddressStreet="+encodeURIComponent(v["BusinessAddressStreet"])+
"&BusinessAddressCity="+encodeURIComponent(v["BusinessAddressCity"])+
"&BusinessAddressPostalCode="+encodeURIComponent(v["BusinessAddressPostalCode"])+
"&BusinessAddressState="+encodeURIComponent(v["BusinessAddressState"])+
"&BusinessAddressCountry="+encodeURIComponent(v["BusinessAddressCountry"])+
"&BusinessTelephoneNumber="+encodeURIComponent(v["BusinessTelephoneNumber"])+
"&BusinessFaxNumber="+encodeURIComponent(v["BusinessFaxNumber"])+
"&MobileTelephoneNumber="+encodeURIComponent(v["MobileTelephoneNumber"])+
"&Email2Address="+encodeURIComponent(v["Email2Address"])+
"&Module=OutLook";
xmlHttp.send(data);
}
if(colContacts.count>0)
alert('Outlook Address imported Successfully');
}
else
{
alert("Your browser does not support to import from outlook \n please use 'internet explorer' browser.");
}
return false;
}
catch(e)
{
alert("If MS Outlook is already there\nplease try the following steps:\nClick on Tools (Menu)=>Internet options=>\n=>Security (Tab)=>Internet=>Custom level=>\nChoose 'Enable' from 'initialize and script Activex controls not marked as safe'");
return false;
}
}

3 comments:

Partha S Bhadra said...

hi samir...
that s a great job....

Krutibash said...

Hi Samir,
Thanks!!!!
It's working perfectly...

Anukampa said...

hello..
u r really a good developer...
keep your achivments