Click here to Skip to main content
Click here to Skip to main content

Lotus Notes Integration with Microsoft .NET Platform (C#)

By , 23 Apr 2007
 
Sample Image - maximum width is 600 pixels

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

  1. Open Microsoft Visual Studio .NET.
  2. 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.
  3. Add controls to your form

In our sample code, we have added few textboxes for configuration of Lotus Notes client, a Button to Start Searching contacts and a Listbox control to list out the results.

  1. In the Solution Explorer, right-click on your project references. 
  2. Choose Add --> Add Reference.
  3. Select Browse button under .NET --> Select the Interop.Domino.dll. (This DLL can be found in the sample code.)
  4. We are ready to go and integrate Lotus Notes capabilities into our application.
  5. First we need to create a session for communicating with Lotus Notes client and dominos server
  6. //
    //
    Code snippet for establishing a Lotus notes session
    //
    //Lotus Notes Object Creation
    _lotesNotesSession = new Domino.NotesSessionClass();
    //Initializing Lotus Notes Session
    _lotesNotesSession.Initialize( NotesPassword );
    //Creating Lotus Notes DataBase Object
    _localDatabase = _lotesNotesSession.GetDatabase( "", "names.nsf", false );
    //creating Lotus Notes Contact View
    _contactsView = _localDatabase.GetView( "Contacts" );
    if( FetchServerData )
    { _lotusNotesServerSession = new Domino.NotesSessionClass();
      _lotusNotesServerSession.Initialize( NotesPassword );
      //Creating Lotus Notes DataBase Object
      _serverDatabase = _lotusNotesServerSession.GetDatabase
    		( DominoServerName, "names.nsf", false );
      //creating Lotus Notes Contact View
      _peopleView = _serverDatabase.GetView( "$People" ); }
    
    }//end if(FetchServerData )  

    (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.)

  7. Now after establishing a session, we need to iterate through various views to fetch the desired data:
  8. //
    //
    //Code snippet for iterating through the views and fetching data
    //
        NotesViewEntryCollection  notesViewCollection =LotusNotesView.AllEntries;
        for( int rowCount = 1; rowCount <= notesViewCollection.Count; rowCount++ )
        {
            //Get the nth entry of the selected view according to the iteration.
            NotesViewEntry viewEntry = notesViewCollection.GetNthEntry( rowCount );
            //Get the first document of particular entry.
            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 );
    
                //compare field value with specific value entered by user
                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();
                            //For FirstName
                            if( searchedNotesItem.Name == "FirstName" )
                                contact.FirstName= searchedNotesItem.Text;
    
                            //For LastName
                            if( searchedNotesItem.Name == "LastName" )
                                contact.LastName = searchedNotesItem.Text;
                            //For Office Phone Number
                            if( searchedNotesItem.Name == "OfficePhoneNumber" )
                                contact.OfficePhoneNumber = searchedNotesItem.Text;
    
                            if( searchedNotesItem.Name  == "InternetAddress" )
                                contact.EmailId = searchedNotesItem.Text;
    
                        }//end for
                        contactsList.Add( contact );
                        break;
                    }//End if
                }
            }
        }

    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

//
//
//Code snippet for popping open a document/contact in lotus notes client
//
//ContactId is the Main thing :
//this is the universaldocumentID which uniquely identifies this
//if the contacts is on the server

if( IsServerData )
{
	notesUrl="Notes://"+LotusNotesServer+"/names.nsf/0/"+ContactId;
}
else
{    //local data
	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

Sample Image - maximum width is 600 pixels

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Aditya P Gupta
Web Developer
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow to read mails from NotesDatabase objectmemberdarshanjbhatt22 Apr '13 - 2:01 
Once we get the NotesDatabase object, how can we read mails from the same. I am trying to do this
 
GetView("Mail") but it coming as null, where as GetView("Calendar") works just fine.
 
My requirement is find a particular mail in Lotus Notes ( based on subject or sender name) and download an attachment within.
 
Any pointer to achieve this.
QuestionUsing Interop.Domino.dll without Lotus client installedmemberantipirat8 Oct '12 - 1:17 
Have you ever tried to use Interop.Domino.dll without Lotus client installed?
AnswerRe: Using Interop.Domino.dll without Lotus client installedmemberdarshanjbhatt7 May '13 - 23:46 
Yes. It works even if Lotus Notes client is not installed or configured.
QuestionView Name for To Do ListmemberMember 94680023 Oct '12 - 19:24 
Hi Aditya,
I have started working on Lotus Notes and want to retrieve items in To Do List on the lotus notes client. Can you please tell me in which database are they stored and under what default view name? I have tried to search a lot but to no avail. Any help will be highly appreciated.
QuestionSMS from Lotus NotesmemberWilsonLast14 May '12 - 19:56 
Hi,
 
You may also check how to send sms from lotus notus with Ozeki NG SMS Gateway:
http://www.sms-integration.com/p_71-lotus-notes-sms.html
 
Youtube link: http://www.youtube.com/watch?v=K6ZQ5eQWcyk
 
BR

QuestionHow to test Lotus Notes Integration with Microsoft .NET Platform (C#)?membersawasthi28 Mar '12 - 22:43 
Hi,
 
Thanks for posting the code on the code project.
 
We need exactly what you did but our problem is that how to test it without having lotus notes? We have exchange server and there is no way to test the application that we did and has the possibility of sending and receiving emails on Lotus notes.
 
Please advise.
 
Thanks in advance
Shailesh
QuestionHow can i read Lotus Notes Database Items with .Net (C#) without installing Lotus Notes on my System ?memberTRON_VS_NEO19 Dec '11 - 11:43 
Dear Gupta,
 
thank you for the great Article it is really great.
 
Let me ask you an question :
 
How can i read Lotus Notes Database Items with .Net (C#) without installing Lotus Notes on my System ?
 
In my Company i'll realize a solution which should run on an Windows 2008 Server but i can't install an Lotus Notes client.
 
Normaly you're able to read all information from an Lotus Notes viwe by activating Http on Domino Server and open the view in the Browser.
 
This is also not possible in my company.
 
I have to accesss Lotus Notes Database Items without installing Lotus Notes Client and without activating Http on Domino.
 
Do you have any information for me.
 
Thank you.
QuestionPerformance Issue : Please HelpmemberBryan Ruddy20 Oct '11 - 5:23 
I have a domino database where I am pulling the records into Excel. The code I wrote works but the performance is very slow. Is there something I can do to speed up the performance?
 
   NotesViewEntryCollection viewEntryColl = notesView.AllEntries;
            NotesViewEntry viewEntry1 = viewEntryColl.GetFirstEntry();
 
            for (int rowCount = 1; rowCount <= viewEntryColl.Count; rowCount++)
            {
                int h = 1;
                foreach (object colValue in viewEntry1.ColumnValues)
                {
                    var cell = (Range)worksheet.Cells[j, h];
                  //  list.Add(colValue);
                   cell.Value2 = colValue;
                    h++;
                }
                viewEntry1 = viewEntryColl.GetNextEntry(viewEntry1);
                j++;
            }

QuestionAccessing Groups from Lotus Notes using Domino.dll and C#.memberPreeeti0824 Oct '09 - 0:28 
Hi,
 
I am trying to access Groups as follows.
 
_groupView = _localDatabase.GetView( "Groups" );
 
But getting null vaues even when my "names.nsf" contains Groups.
 

 
Regards,
Preeti
GeneralTrouble wih version of Lotus Notesmemberphenix_28 Aug '09 - 1:51 
Hi Gupta,
 
With Lotus Notes 8.5, your example works fine.But with Lotus 5.0.10 and probably Lotus 6 the cast:
NotesItem notesItem = (Domino.NotesItem)itemArray.GetValue( itemCount );
don't work.(Interface missed)
So I try to use a better way to do the same thing. Have you any idea about that ?
 
Regards.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 23 Apr 2007
Article Copyright 2007 by Aditya P Gupta
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid