Getting Data From Lotus Notes Through ASP MVC

In this article, we will learn how to get the data from Lotus Notes view and display the records, using ASP MVC list.

Introduction about Lotus Notes 

Lotus Notes is a brand of Groupware, which is now owned by IBM. Lotus Notes is used with a variety of local and collaborative server applicatios, including email, calendars, Personal Information Managers (PIM) and the Web.

To know more about Lotus Notes, find the link.

Step 1

Create a simple form in Lotus Notes to save the records in Lotus notes database. Here, I have created the database "Migration.nsf" and created a form "StudentInformations" to save the student details in Lotus notes.

 

Steps 2

Insert the records once the form has been designed and create Lotus Notes view to display the saved records.

 

Step 3

Create a ASP MVC project . Here, I have created a project named "LotusNotestoASPMvc", using Visual Studio 2013.

 

Step 4

Click OK and dialog Window will appear to select the Application type. Select MVC and Click OK.

 

Step 4

Once the project has been created, you can find the project solution files in the right corner of VS2013.

 

Step 5

To access Lotus Notes in Visual studio, we have to add "Interop.Domino" file in our reference folder. To get "Interop.Domino" library file, proceed, as shown below.

Go to Tools -> NuGet Package Manager -> Manage NuGet package for Solution.



Step 6

Now, you can see the dialog Window, which contains "Installed packages"(already installed components), Online (Get components from online). Click Online tab and search the text as "Domino" in search box. Select the "Interop.Domino.dll" and click install button to add the Domino component in our reference folder.



Step 7

Now, you can see the installed "Interop.Domino.dll" in our reference folder.

 

Step 8

Create a model , select Model Folder > Right Click -> Add new class and name it as "StudentDetails" and click ok. Now, write the code given below in your model.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. namespace LotusNotesTOASPMvc.Models {  
  6.     public class StudentDetails {  
  7.         public string StudentName {  
  8.             get;  
  9.             set;  
  10.         }  
  11.         public double Age {  
  12.             get;  
  13.             set;  
  14.         }  
  15.         public string City {  
  16.             get;  
  17.             set;  
  18.         }  
  19.         public string Address {  
  20.             get;  
  21.             set;  
  22.         }  
  23.         public string PhoneNo {  
  24.             get;  
  25.             set;  
  26.         }  
  27.     }  
  28. }  
Step 9

Create a controller to get Lotus Notes data and bind them to our model. To create a controller, select Controller Folder -> Right click -> select controller -> Select MVC Empty controller -> Click OK.

Now, add the code given below in your controller.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6. using Domino; // To access the Domino classes  
  7. using LotusNotesTOASPMvc.Models; // to access the models  
  8. namespace LotusNotesTOASPMvc.Controllers {  
  9.     public class StudentInformationsController: Controller {  
  10.         NotesSession session = new NotesSession(); // Notes Session Object  
  11.         NotesDatabase db;  
  12.         NotesView view;  
  13.         NotesDocument doc;  
  14.         public ActionResult Index() {  
  15.             session.Initialize("password@#123"); // Notes Password for your Notes Id  
  16.             db = session.GetDatabase("""Migration.nsf"false);  
  17.             view = db.GetView("vwStudentInformations"); // View name  
  18.             doc = view.GetFirstDocument(); // get the first document  
  19.             List < StudentDetails > student = new List < StudentDetails > ();  
  20.             while (doc != null) {  
  21.                 string Name = doc.GetItemValue("txName")[0];  
  22.                 double Age = doc.GetItemValue("txAge")[0];  
  23.                 string City = doc.GetItemValue("txCity")[0];  
  24.                 string Address = doc.GetItemValue("txAddress")[0];  
  25.                 string PhoneNo = doc.GetItemValue("txPhoneNo")[0];  
  26.                 student.Add(new StudentDetails // Bind the data to model  
  27.                     {  
  28.                         StudentName = Name,  
  29.                             Age = Age,  
  30.                             City = City,  
  31.                             Address = Address,  
  32.                             PhoneNo = PhoneNo  
  33.                     });  
  34.                 doc = view.GetNextDocument(doc); // Looping the next document  
  35.             }  
  36.             return View(student);  
  37.         }  
  38.     }  
  39. }  
Step 10

Create a MVC view to show the records. To create a view, right click the controller action name "Index" -> Add View -> Select List in Scafolding template -> Select your Model and click OK. Your view will be created.



 

Step 11

Build your Application and click CTRL+ F5 to run the Application.

Result


Similar Articles