Read Lotus Notes using C#

This short article shows you that the C# code that can work with Lotus Notes.

It took me awhile to find a working C# sample code. Google finally landed my at When I looked at the article is back in 2007. At that time, the Visual Studio should be 2005 and .NET Framework 2.0. At Lotus Notes side the version should be 6.x.

Let look at the most import 2 piece of code in this article. To get the Lotus Notes nsf file and get the View which is the code below.



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 ) 


To loop through the View.

//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 );
                }//End if


I tested it in Visual Studio 2013 and Lotus Notes 8.5.3 somehow it is still working.

You might hit the error “COM Error 80004005”. See this for information

You can also download the source code from The sample file name My MSN ID is

About chanmingman

Since March 2011 Microsoft Live Spaces migrated to Wordpress ( till now, I have is over 1 million viewers. This blog is about more than 50% telling you how to resolve error messages, especial for Microsoft products. The blog also has a lot of guidance teaching you how to get stated certain Microsoft technologies. The blog also uses as a help to keep my memory. The blog is never meant to give people consulting services or silver bullet solutions. It is a contribution to the community. Thanks for your support over the years. Ming Man is Microsoft MVP since year 2006. He is a software development manager for a multinational company. With 25 years of experience in the IT field, he has developed system using Clipper, COBOL, VB5, VB6, VB.NET, Java and C #. He has been using Visual Studio (.NET) since the Beta back in year 2000. He and the team have developed many projects using .NET platform such as SCM, and HR based applications. He is familiar with the N-Tier design of business application and is also an expert with database experience in MS SQL, Oracle and AS 400.
This entry was posted in .Net, Community and tagged , , , . Bookmark the permalink.

One Response to Read Lotus Notes using C#

  1. Pingback: How to see how many Forms in Lotus Notes database | Chanmingman's Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s