) Lotus Notes integration with Microsoft. NET platform (C #)

Source: Internet
Author: User
Tags rowcount

Http://www.codeproject.com/KB/cs/lotusnoteintegrator.aspx

 

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 syntax ages 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 AndNotesDocument. 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 clients 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 orInterOP. 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:
    ChooseNew-->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 fewtextboxEs for configuration of Lotus Notes client, a button to start searching contacts andListbox Control to list out the results.

  1. InSolution Explorer, Right-click on your project references.
  2. ChooseAdd --> Add reference.
  3. SelectBrowse button under. Net -->SelectInterOP. 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
    ////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 UsernameAs the last user login into lotus client is always taken as the userid .)

  6. Now after establishing a session, We Need To iterate through varous views to fetch the desired data:
    //////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 snippetNotesViewEntry, 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 serverif( IsServerData ){notesUrl="Notes://"+LotusNotesServer+"/names.nsf/0/"+ContactId;}else{    //local datanotesUrl="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 );} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.