Introduction
The article describes with the help of a Windows application how Lotus Notes can be integrated with .NET using Lotus Notes Interop.
Background
The Lotus Notes .NET Interop provides a way of communication between the Microsoft .NET platform and Lotus Notes client and dominos server. It supports access to Lotus Notes documents and views, and allows you to write various applications, for example, Web form, Windows form, and console applications within Microsoft Visual Studio .NET. You can use all Common Language Runtime (CLR) programming languages such as Visual Basic .NET, C#, or Managed C++.
At runtime, the Lotus Notes interop fetches the data as requested using the Interop classes, i.e. NotesViewEntryCollection
, NotesViewEntry
and NotesDocument
. These classes for Lotus Notes clients provides .NET developers with a familiar way to use Lotus Notes functionality. Using the code, developers can access Lotus Notes documents and can integrate Lotus Notes capabilities to any external applications.
This article assumes that you have basic understanding of Lotus Notes.
Prerequisites
- Windows 2000 or Windows XP
- Microsoft Visual Studio .NET
- Lotus Notes client installed or Interop.Domino.dll
- Basic understanding of Lotus Notes.
Create a C# Application using Lotus Notes Connector
The example demonstrates how to fetch information regarding 'Contacts' from user contacts and central contacts database.
Procedure
- Open Microsoft Visual Studio .NET.
- Create a new C# Windows application project:
Choose New --> New Project ?--> Visual C# Projects ?--> Windows Application.
You can also create a project in any other common programming language.
- Add controls to your form
In our sample code, we have added few textbox
es for configuration of Lotus Notes client, a Button to Start Searching contacts and a Listbox
control to list out the results.
- In the Solution Explorer, right-click on your project references.
- Choose Add --> Add Reference.
- Select Browse button under .NET --> Select the Interop.Domino.dll. (This DLL can be found in the sample code.)
- We are ready to go and integrate Lotus Notes capabilities into our application.
- First we need to create a session for communicating with Lotus Notes client and dominos server
Code snippet for establishing a Lotus notes session
_lotesNotesSession = new Domino.NotesSessionClass();
_lotesNotesSession.Initialize( NotesPassword );
_localDatabase = _lotesNotesSession.GetDatabase( "", "names.nsf", false );
_contactsView = _localDatabase.GetView( "Contacts" );
if( FetchServerData )
{ _lotusNotesServerSession = new Domino.NotesSessionClass();
_lotusNotesServerSession.Initialize( NotesPassword );
_serverDatabase = _lotusNotesServerSession.GetDatabase
( DominoServerName, "names.nsf", false );
_peopleView = _serverDatabase.GetView( "$People" ); }
}
(Please take note here that while establishing a session, we only provide userpassword and servername, we don't provide username as the last user login into Lotus client is always taken as the userId.)
- Now after establishing a session, we need to iterate through various views to fetch the desired data:
NotesViewEntryCollection notesViewCollection =LotusNotesView.AllEntries;
for( int rowCount = 1; rowCount <= notesViewCollection.Count; rowCount++ )
{
NotesViewEntry viewEntry = notesViewCollection.GetNthEntry( rowCount );
NotesDocument document = viewEntry.Document;
object documentItems = document.Items;
Array itemArray1 = (System.Array)documentItems;
for( int itemCount=0 ; itemCount< itemArray1.Length; itemCount++ )
{
NotesItem notesItem =
(Domino.NotesItem)itemArray1.GetValue( itemCount );
if( notesItem.Text !=null )
{
if( (notesItem.Text.ToUpper()).StartsWith( fieldValue ))
{
Contact contact = new Contact();
for( int icount=0 ; icount< itemArray1.Length; icount++ )
{
NotesItem searchedNotesItem =
(Domino.NotesItem)itemArray1.GetValue( icount );
string FieldName = searchedNotesItem.Name.ToString();
if( searchedNotesItem.Name == "FirstName" )
contact.FirstName= searchedNotesItem.Text;
if( searchedNotesItem.Name == "LastName" )
contact.LastName = searchedNotesItem.Text;
if( searchedNotesItem.Name == "OfficePhoneNumber" )
contact.OfficePhoneNumber = searchedNotesItem.Text;
if( searchedNotesItem.Name == "InternetAddress" )
contact.EmailId = searchedNotesItem.Text;
}
contactsList.Add( contact );
break;
}
}
}
}
If you see in the above code snippet NotesViewEntry, NotesDocument, NotesItem
classes are used to create the objects for Lotus Notes driver data access. So the code snippet and the sample application demonstrates how easily one can integrate Lotus Notes accessing capabilities into an application.
How to Pop Open a Contact in Lotus Notes
if( IsServerData )
{
notesUrl="Notes://"+LotusNotesServer+"/names.nsf/0/"+ContactId;
}
else
{
notesUrl="Notes:///names.nsf/0/"+ContactId;
}
string lotusNotesPath = ReadRegistry();
if( lotusNotesPath!="" )
{
lotusNotesPath = lotusNotesPath+"notes";
System.Diagnostics.Process process =
new System.Diagnostics.Process();
System.Diagnostics.Process.Start( lotusNotesPath,notesUrl );
System.Threading.Thread.Sleep( 500 );
}
History
- 23rd April, 2007: This is the first draft of the application.
I will try and update this to further integrate with other Lotus Notes document types.
About Aditya Gupta
I am currently working in an outsourced software product development company, PROTEANS SOFTWARE SOLUTIONS LTD.(www.proteans.com) as a Technical Leader. I have around 6 years of experience in the software industry, mainly telecom, computer telephony integration. I have experience in VC++, MFC and in Microsoft .NET technologies(C#).
About Proteans Software Solutions
Proteans is an outsourcing company focusing on software product development and business application development on Microsoft Technology Platform. Proteans partners with Independent Software Vendors (ISVs), System Integrators and IT teams of businesses to develop software products. Our technology focus and significant experience in software product development - designing, building, and releasing world-class, robust and scalable software products help us to reduce time-to-market, cut costs, reduce business risk and improve overall business results for our customers. Proteans expertises in development using Microsoft .NET technologies.
Acknowledgements
Special thanks to Pankaj Pahuja (pankaj_proteans@hotmail.com) for his inputs and guidance on Lotus Notes client and how to get going with Lotus Interop.