Thursday, August 17, 2006

Programmatically export Lotus Notes contacts to VCard format

Lotus Notes 6 makes it possible to export contacts to VCard format. You can do it using File-Export menu. In the Export dialog box you can choose to export to VCard 2.1/3.0 format. After that you can import the resulting VCF file into Outlook.

But sometimes you would like to modify the format which the automated function uses. For example instead of "FirstName LastName/Company/Country" format in VCard's FN field you want to use simply "FirstName LastName", or you want to make a lookup to fetch the required field value.
"Export to VCard" option is available only in the databases of type "Domino Directory", you can not see that export option in regular Domino databases where you might have people documents.

Here is a LotusScript agent which runs on selected documents in any database and exports them to VCard fromat. The agent expects that the names of the fields in the documents are the same as in Address Book's "Person" form, so if you used other field names you must modify the agent. The agent's "Target" property is "All selected documents". Agent is run by choosing agent's name in the actions menu in a view after you've selected the documents you want to export.


'------------- AGENT START -----------
Sub Initialize
Dim session As New NotesSession
Dim nabdb As NotesDatabase
Dim nabdoc As NotesDocument
Dim nabcoll As NotesDocumentCollection
Dim vcardfile As String
Dim result As String
Dim linebreak As String
Dim fileNum As Integer

linebreak=Chr(13)+Chr(10)
vcardfile="c:\lotus_notes_contacts.vcf"

Set nabdb=session.CurrentDatabase
Set nabcoll=nabdb.UnprocessedDocuments
Print "Exporting"+Cstr(nabcoll.Count)+" documents to VCard "+vcardfile

If nabcoll.Count=0 Then Exit Sub

fileNum% = Freefile()
Open vcardfile For Output As #fileNum%

Set nabdoc=nabcoll.GetFirstDocument
While Not nabdoc Is Nothing

result="BEGIN:VCARD"+linebreak+ "VERSION:2.1"

result=result+linebreak+ "N:"+nabdoc.LastName(0)+";"+nabdoc.FirstName(0)+";"+nabdoc.MiddleName(0)+";"+nabdoc.Title(0)
If nabdoc.MiddleName(0)="" Then
FullName=nabdoc.FirstName(0)+" "+nabdoc.LastName(0)
Else
FullName=nabdoc.FirstName(0)+" "+nabdoc.MiddleName(0)+" "+nabdoc.LastName(0)
End If
result=result+linebreak+"FN:"+FullName
' result=result+linebreak+"NICKNAME:"+FullName
result=result+linebreak+"ORG:"+nabdoc.CompanyName(0)+";"+nabdoc.Department(0)
result=result+linebreak+"TITLE:"+nabdoc.JobTitle(0)
result=result+linebreak+"NOTE:"+nabdoc.Comment(0)
result=result+linebreak+"TEL;WORK;VOICE:"+nabdoc.OfficePhoneNumber(0)
result=result+linebreak+"TEL;HOME;VOICE:"+nabdoc.PhoneNumber(0)
result=result+linebreak+"TEL;CELL;VOICE:"+nabdoc.CellPhoneNumber(0)
result=result+linebreak+"TEL;WORK;FAX:"+nabdoc.OfficeFaxPhoneNumber(0)
result=result+linebreak+"TEL;HOME;FAX:"+nabdoc.HomeFAXPhoneNumber(0)
result=result+linebreak+"ADR;WORK:;"+nabdoc.OfficeCity(0)+";"+replaceLineBreak(nabdoc.OfficeStreetAddress(0))+";"+nabdoc.OfficeCity(0)+";"+nabdoc.OfficeState(0)+";"+nabdoc.OfficeZIP(0)+";"+nabdoc.OfficeCountry(0)
result=result+linebreak+"ADR;HOME:;;"+replaceLineBreak(nabdoc.StreetAddress(0))+";"+nabdoc.City(0)+";"+nabdoc.State(0)+";"+nabdoc.Zip(0)+";"+nabdoc.Country(0)
' result=result+linebreak+"URL;WORK:"+nabdoc.WebSite(0)
result=result+linebreak+"URL;HOME:"+nabdoc.WebSite(0)
result=result+linebreak+"PREF;INTERNET:"+nabdoc.InternetAddress(0)
result=result+linebreak+"EMAIL;INTERNET:"+nabdoc.MailAddress(0)

result=result+linebreak+"END:VCARD"

Print #fileNum%, result

Set nabdoc=nabcoll.GetNextDocument(nabdoc)
Wend

Close #fileNum%

End Sub


Function replaceLineBreak(oldString)
replaceFrom=Chr(13)+Chr(10)
replaceTo=", "
tmpString = Evaluate(|@ReplaceSubstring("| + oldString + |"; "|+replaceFrom+|"; "|+replaceTo+|")|)
replaceLineBreak=tmpString(0)
End Function

'------------- AGENT END -----------


Technorati:

26 comments:

Stefan said...

How can I import from exchange 2003 to Lotus notes adressbok ?

Andrei Kouvchinnikov said...

Hello Stefan,
Unfortunately I don't have the Exchange 2003, so I don't know how the file looks like. Send me an example file and I'll take a look at it.

md_gmail said...

Any idea why it might only grab one contact from my contacts? It appears the while loop is not working. I'm new to notes, so I don't know how to step through agent code...

Thanks, Mark

Ayyanar said...

I would like extract contacts list from the lotus notes using domino in C#.Net.

CODE:
-----
NotesSession NotesApp = new NotesSession();
NotesDatabase NotesDB = null;
NotesDocument doc = null;
NotesDocumentCollection docColl;
StringBuilder c = new StringBuilder();

try
{
NotesApp.Initialize("");

NotesDB = NotesApp.CurrentDatabase;
docColl = NotesDB.UnprocessedDocuments;


doc = docColl.GetFirstDocument();

while (doc != null)
{
c.Append(doc.GetFirstItem("FirstName"));

doc = docColl.GetNextDocument(doc);
}

MessageBox.Show(c.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

}
finally
{

}



----------------------

the above code is not working perfectly. i am getting exception in docColl = otesDB.UnprocessedDocuments; line.

Please advice how to extract contacts inforamtion .Net.

My mail ID (ayyanarj@gmail.com).

Advance Thanks
Ayyanar. J

Andrei Kouvchinnikov said...

Ayyanar, I think you can not use CurrentDatabase or UnprocessedDocuments property for this in C#.
I would try with something like this:

NotesDB = NotesApp.GetDatabase("","mydb.nsf");
docColl = NotesDB.AllDocuments;

or:
docColl = NotesDB.Search("Form="+chr(34)+"test"+chr(34), 0);

Andrei Kouvchinnikov said...

Mark, the code runs on selected documents. So you must select several documents in the view, otherwise it runs only on currently selected 1 document.

dhd said...

Youth is warcraft leveling not a time of life;warcraft leveling it is a wow lvl state of mind; wow power level it is not power leveling amatter of World of warcraft Power Leveling rosy cheeks, red wrath of the lich king power leveling lips and supple knees;WOTLK Power Leveling it is a matter of thewill,wlk Power Leveling a quality of buy aoc gold the imagination,aoc gold a vigor of the emotions; it is thefreshness of the deep springs of life. Youth means a tempera-mental maplestory mesos predominance of courage over timidity, of the appetite formaple story mesos adventure over the love of ease. This often existsin a man of 60 more than a boy of 20. Nobody grows old merely by anumber of years.

xxmy said...

Weekends to peopleig2tmean that they can have a two-day wowgold4europe good rest. For example, people gameusdcan go out to enjoy themselves or get meinwowgoldtogether with relatives and friends to talk with each storeingameother or watch interesting video tapes with the speebiewhole family.
Everyone spends agamegoldweekends in his ownmmoflyway. Within two days,some people can relax themselves by listening to music, reading novels,or watchingogeworld films. Others perhaps are more active by playing basketball,wimming ormmorpgvipdancing. Different people have different gamesavorrelaxations.
I often spend weekends withoggsalemy family or my friends. Sometimes my parents take me on a visit to their old friends. Sometimesgamersell I go to the library to study or borrow some books tommovirtexgain much knowledge. I also go to see various exhibition to broadenrpg tradermy vision. An excursion to seashore or mountain resorts is my favorite way of spending weekends. Weekends are always enjoyable for me.
igxe swagvaultoforu wowgold-usaignmax wowgoldlivebrogame thsaleGoldRockUbrogameswagvaultgoldsoonoforuigxethsale

dreaz said...

I am grateful to you for this great content.aöf thanks radyo dinle cool hikaye very nice ssk only cinsellik very nice ehliyet only home free kadın last go korku jomax med olsaoy hikaye lesto go müzik dinle free only film izle love aşk only mp3 indir only radyolar lest go açıköğretim free net only filmler

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.

Bruce said...

Today,we are proud to announce the launch of the new wedding support service sell ffxi gil,packed with features sure to sell ffxi gils delight adventurers across Vana'diel looking to exchange eternal vows with their beloved!Responding to player demands for greater customization,the new service will grant brides and grooms freedom in choosing location,timing,dialogue,and sell Final Fantasy XI Gil more for their ceremony,allowing them to create a truly memorable event all their own.Information on all the features,including in-game sell ffxi gil item vendors and wedding certificates,can be found on the new wedding support site,so head on over sell ffxi gils and get started planning the wedding of your dreams sell Final Fantasy XIGil!

Anonymous said...

o‰ï‚¢‹i’ƒo‰ï‚¢ƒJƒtƒFƒeƒŒƒNƒ‰•s—σZƒbƒNƒXƒtƒŒƒ“ƒhƒZƒtƒŒo‰ï‚¢o‰ï‚¢o‰ï‚¢ŒfŽ¦”o‰ï‚¢o‰ï‚¢o‰ï‚¢lÈ•—‘­ƒfƒŠƒwƒ‹ƒfƒŠƒoƒŠ[ƒwƒ‹ƒXo‰ï‚¢o‰ï‚¢–³—¿ƒtƒBƒŠƒsƒ“ƒ‰ƒCƒuƒ`ƒƒƒbƒgƒAƒ_ƒ‹ƒgƒ‰ƒCƒuƒ`ƒƒƒbƒgƒfƒŠƒwƒ‹

Anonymous said...

•s“®ŽYƒ\[ƒvƒ‰ƒ“ƒhƒAƒNƒZƒXƒJƒEƒ“ƒ^[ƒRƒŒƒXƒeƒ[ƒ‹’†«Ž‰–b‰Ô•²ÇÝ‘[ƒN“àEÝ‘îƒAƒ‹ƒoƒCƒgŠ£‘‡”§ƒ_ƒCƒGƒbƒg@HŽ–ƒTƒvƒŠƒƒ“ƒg–³—¿è‚¢o‰ï‚¢ŽRŒûƒNƒŒƒWƒbƒgƒJ[ƒhŒ»‹à‰»ƒNƒŒƒWƒbƒgŒ»‹à‰»ƒ‰ƒCƒuƒ`ƒƒƒbƒgƒtƒBƒŠƒsƒ“ƒ`ƒƒƒbƒgƒŒƒfƒBƒpƒ\ƒRƒ“Ý‘[ƒN

Anonymous said...

ƒjƒLƒrCholesterol…’Ž—₦«‚Þ‚­‚ÝŽYŒã‚í‚«‚ªŽÔ”ƒŽæ“]E‰Á—îL“V‘RƒIƒŠƒS“œ’ܐ…’Ž‹ž“s‚«‚à‚̍ݑîŽdŽ–

Anonymous said...

o‰ï‚¢ŒF–{o‰ï‚¢‹ž“so‰ï‚¢ŽOdo‰ï‚¢‹{éo‰ï‚¢‹{èo‰ï‚¢’·–ìo‰ï‚¢’·èo‰ï‚¢“ޗǏo‰ï‚¢VŠƒo‰ï‚¢‘啪o‰ï‚¢‰ªŽRo‰ï‚¢‰«“êo‰ï‚¢‘åão‰ï‚¢²‰êo‰ï‚¢é‹Êo‰ï‚¢Ž ‰êo‰ï‚¢“‡ªo‰ï‚¢Ã‰ªo‰ï‚¢“Ȗ؏o‰ï‚¢“¿“‡

Anonymous said...

o‰ï‚¢“Œ‹žo‰ï‚¢’¹Žæo‰ï‚¢•xŽRo‰ï‚¢˜a‰ÌŽRo‰ï‚¢ŽRŒ`o‰ï‚¢ŽRŒûo‰ï‚¢ŽR—œo‰ï‚¢–k‹ãBo‰ï‚¢‰ºŠÖo‰ï‚¢ìèo‰ï‚¢_ŒËo‰ï‚¢‹v—¯•Äo‰ï‚¢…ŒËo‰ï‚¢–¼ŒÃ‰®o‰ï‚¢‘å–´“co‰ï‚¢é‹Êo‰ï‚¢äo‰ï‚¢å‘äo‰ï‚¢‰¡•lo‰ï‚¢‰¡{‰êo‰ï‚¢ŽD–yo‰ï‚¢ìè

Anonymous said...

•Ÿˆäo‰ï‚¢ˆ¤’mo‰ï‚¢Šò•Œo‰ï‚¢Ã‰ªo‰ï‚¢ŽOdo‰ï‚¢•ºŒÉo‰ï‚¢‘åão‰ï‚¢˜a‰ÌŽRo‰ï‚¢Ž ‰êo‰ï‚¢‹ž“so‰ï‚¢“ޗǏo‰ï‚¢ŽRŒûo‰ï‚¢’¹Žæo‰ï‚¢“‡ªo‰ï‚¢‰ªŽRo‰ï‚¢L“‡o‰ï‚¢“¿“‡o‰ï‚¢ìo‰ï‚¢ˆ¤•Qo‰ï‚¢‚’mo‰ï‚¢

Anonymous said...

o‰ï‚¢ŒF–{o‰ï‚¢‹ž“so‰ï‚¢ŽOdo‰ï‚¢‹{éo‰ï‚¢‹{èo‰ï‚¢’·–ìo‰ï‚¢’·èo‰ï‚¢“ޗǏo‰ï‚¢VŠƒo‰ï‚¢‘啪o‰ï‚¢‰ªŽRo‰ï‚¢‰«“êo‰ï‚¢‘åão‰ï‚¢²‰êo‰ï‚¢é‹Êo‰ï‚¢Ž ‰êo‰ï‚¢“‡ªo‰ï‚¢Ã‰ªo‰ï‚¢“Ȗ؏o‰ï‚¢“¿“‡

Anonymous said...

•Ÿˆäo‰ï‚¢ƒJƒtƒFˆ¤’mo‰ï‚¢ƒJƒtƒFŠò•Œo‰ï‚¢ƒJƒtƒFÃ‰ªo‰ï‚¢ƒJƒtƒFŽOdo‰ï‚¢ƒJƒtƒF•ºŒÉo‰ï‚¢ƒJƒtƒF‘åão‰ï‚¢ƒJƒtƒF˜a‰ÌŽRo‰ï‚¢ƒJƒtƒFŽ ‰êo‰ï‚¢ƒJƒtƒF‹ž“so‰ï‚¢ƒJƒtƒF“ޗǏo‰ï‚¢ƒJƒtƒFŽRŒûo‰ï‚¢ƒJƒtƒF’¹Žæo‰ï‚¢ƒJƒtƒF“‡ªo‰ï‚¢ƒJƒtƒF‰ªŽRo‰ï‚¢ƒJƒtƒFL“‡o‰ï‚¢ƒJƒtƒF“¿“‡o‰ï‚¢ƒJƒtƒFìo‰ï‚¢ƒJƒtƒFˆ¤•Qo‰ï‚¢ƒJƒtƒF‚’mo‰ï‚¢ƒJƒtƒF

Anonymous said...

•ŸˆäƒeƒŒƒNƒ‰ˆ¤’mƒeƒŒƒNƒ‰Šò•ŒƒeƒŒƒNƒ‰Ã‰ªƒeƒŒƒNƒ‰ŽOdƒeƒŒƒNƒ‰•ºŒÉƒeƒŒƒNƒ‰‘åãƒeƒŒƒNƒ‰˜a‰ÌŽRƒeƒŒƒNƒ‰Ž ‰êƒeƒŒƒNƒ‰‹ž“sƒeƒŒƒNƒ‰“ޗǃeƒŒƒNƒ‰ŽRŒûƒeƒŒƒNƒ‰’¹ŽæƒeƒŒƒNƒ‰“‡ªƒeƒŒƒNƒ‰‰ªŽRƒeƒŒƒNƒ‰L“‡ƒeƒŒƒNƒ‰“¿“‡ƒeƒŒƒNƒ‰ìƒeƒŒƒNƒ‰ˆ¤•QƒeƒŒƒNƒ‰‚’mƒeƒŒƒNƒ‰

Anonymous said...

•ŸˆäƒZƒtƒŒˆ¤’mƒZƒtƒŒŠò•ŒƒZƒtƒŒÃ‰ªƒZƒtƒŒŽOdƒZƒtƒŒ•ºŒÉƒZƒtƒŒ‘åãƒZƒtƒŒ˜a‰ÌŽRƒZƒtƒŒŽ ‰êƒZƒtƒŒ‹ž“sƒZƒtƒŒ“ޗǃZƒtƒŒŽRŒûƒZƒtƒŒ’¹ŽæƒZƒtƒŒ“‡ªƒZƒtƒŒ‰ªŽRƒZƒtƒŒL“‡ƒZƒtƒŒ“¿“‡ƒZƒtƒŒìƒZƒtƒŒˆ¤•QƒZƒtƒŒ‚’mƒZƒtƒŒ

Anonymous said...

•Ÿˆä•s—ψ¤’m•s—ÏŠò•Œ•s—ϐɪ•s—ÏŽOd•s—Ï•ºŒÉ•s—Ï‘åã•s—Ϙa‰ÌŽR•s—ÏŽ ‰ê•s—Ï‹ž“s•s—Ï“Þ—Ç•s—ÏŽRŒû•s—Ï’¹Žæ•s—Ï“‡ª•s—ωªŽR•s—ύL“‡•s—Ï“¿“‡•s—ύì•s—ψ¤•Q•s—ύ‚’m•s—Ï

Anonymous said...

—D—Ǐo‰ï‚¢ƒTƒCƒgƒAƒ_ƒ‹ƒg“ŽB‘fln—ƒGƒƒAƒjƒAV——Doˆ§‚¢o‡‚¢ŒnƒTƒCƒg‚Å‚ ‚¢deai•s—Ï•s—Ï‚µ‚Ä‚Ý‚Ü‚¹‚ñ‚©•s—σp[ƒgƒi[•s—ψ¤l2ƒVƒ‡ƒbƒgƒ`ƒƒƒbƒgo‰ï‚¢•s—ϐlÈƒNƒŒƒWƒbƒgƒJ[ƒh

game videos said...

Thanks for posting this information, I will show it to my friend, he is huge fan of this. It's been a pleasure to read this post.
Hannah from SheepArcade
If you like to play games, visit sheep arcade and play adventure games and online games for free.

replacement window virginia said...

Thanks for sharing such useful codes I will sure try them.

Beauty Jose said...

Get instant NSF file to PST file converter for recovering and exporting Lotus Notes NSF to Outlook PST, EML and MSG file. Software can split converted PST file with whole versions of Lotus Notes and Outlook.


read more
http://www.nsftopst.exportnsfpst.com/