Solved

Setting up a Lotus Notes Development Environment for C#

Posted on 2010-09-22
18
1,337 Views
Last Modified: 2013-12-18
Well, it's not as easy as I had imagined.  I downloaded and installed the latest version of Lotus Notes
in order to do some development in Visual Studio (C#).  I need to "talk" to notes from our CRM application
and get it to send emails, create appointments and tasks and add/edit contacts.

But right now I'm having a problem just getting started.  I've installed Notes and have manually created
an email, and calendar item, and contact.  Now I want to create a notes session:  Here is my simple start
to the code:

        public static void Test()
        {
            Domino.NotesSession session = new Domino.NotesSession();
            session.Initialize("pw1");
            Domino.NotesDatabase db = session.GetDatabase("", "", true);
       }

When I get to the last line it blows up.  I don't have a domino server installed, I thought I could just
use a local store somehow.  If anyone could direct me on how to setup a development environment
and/or how to get past this part.  Notes doesn't give me any indication as to what the error is it just
says it will contact the help desk or something.  Not very helpful.

Thanks.

Bob
0
Comment
Question by:marketware
  • 9
  • 3
  • 3
  • +1
18 Comments
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 33738866
When you say 'blows up', what do you mean? Is there an exception? I would expect it to throw an error about invalid parameter since you have not specified the database to get.

Here's a bit of code that reads all appointments in your calendar. This example assumes your mail file is on your local computer, is in the mail subfolder (relative to the ...\Notes\Data folder), and is named your_mailfile.nsf.
BTW: if you pass an empty string to NotesSession.Initialize, the API will prompt you at runtime.  Not good for server processes, but good for testing.

private void GetAppointments_Click(object sender, EventArgs e)

        {

            NotesSession sess = new NotesSession();

            sess.Initialize("");

            DateTime rangeStart = new DateTime(2010, 1, 1);

            DateTime rangeEnd = new DateTime(2010, 12, 31);

            NotesDocumentCollection dc = GetAppointmentsInRange(sess, "", "mail\\your_mailfile.nsf", rangeStart, rangeEnd);

            String results = "";

            NotesDocument doc = dc.GetFirstDocument();

            while (doc != null)

            {

                results = results + ((object[])doc.GetItemValue("Subject"))[0] + Environment.NewLine;

                doc = dc.GetNextDocument(doc);

            }

            MessageBox.Show(results);

        }



        private NotesDocumentCollection GetAppointmentsInRange(NotesSession sess, String server, String file, DateTime rangeStart, DateTime rangeEnd)

        {

            NotesDatabase db = sess.GetDatabase(server, file, false);

            String query = "(AppointmentType=\"0\") & (StartDate > [" + rangeStart.ToString("MM/dd/yyyy") + "]) & (StartDate < [" + rangeEnd.ToString("MM/dd/yyyy") + "])";

            NotesDocumentCollection dc = db.Search(query, null, 0);

            return dc;

        }

Open in new window

0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 33738899
Also, have you actually launched Notes yet?  You have to run it once to complete setup.
0
 
LVL 16

Expert Comment

by:kris_per
ID: 33739226


For the actual email-ing to work, you need a Domino server. However you can create and save mail, contact and other items in a local mail database for initial dev and understanding.

First create a local mail database in Lotus Notes I think by using File - Database - New menu item, then Choose Local in the Server field, enter title and name (for example mymail.nsf) and importantly Choose Mail template from from the templates list.

Following link shows a sample code on how to create mail and send (with domino server) => http://www.codeproject.com/KB/cs/LotusNotesWithCS.aspx

To use local mail file:

NotesSession _notesSession = new NotesSession();

NotesDatabase _notesDataBase = _notesSession.GetDatabase("", "mymail.nsf", false); // pass empty for server name

 _notesDataBase.Open( );

NotesDocument _notesDocument = _notesDataBase.CreateDocument();

 _notesDocument.ReplaceItemValue("Form", "Memo"); // Setting Form field to Memo makes this document a mail document

// Set SendTo, Subject, Body fields as shown in the link above

oItemValue = _notesDocument.GetItemValue("SendTo" );

_notesDocument.Send(false, ref oItemValue);

I am not sure if Send method above will work or not as there is no server. If it doesn't throw any error, then it means it has atleast created a mail document which you can see in Lotus Notes opening the mymail.nsf database file in Sent folder.

If Send throws any error, then try with Save method which will atleast save this mail document in the mail database.

For contact items, the Form field should be set to 'Contact' I think and you need to set values for fields specific to Contact. If you right click on a mail in Lotus Notes and select Document Properties and in the Fields tab, you can see all the field names related to a mail document (for example Form field will have value of 'Memo'). I think you can find out required fields and values for contact/appointment items by the same way.

This link also does similar to the above link => http://www.notes411.com/dominosource%5Ctips.nsf/0/2114E009A8C8D089802571B6003CD7C4!opendocument


0
 

Author Comment

by:marketware
ID: 33739381
Yes I have launched Notes.  In fact, I've tested it by adding a Contact, Appointment and received an Email in it.  I really don't get an error message of sorts like you'd normally expect, it displays a window telling me that Notes is having trouble.  I'll attach the window so you can see.

I've modified the code I used earlier and I blow up now on the last line.

      public static void Test(App oApp)
        {
            Domino.NotesSession session = new Domino.NotesSession();
            session.Initialize("");

            NotesDatabase db = session.GetDatabase("", "mail\bbartel.nsf", false);
            Domino.NotesDocument doc = db.CreateDocument();

        }

BTW I tried your code too. and it blows up on this line:

NotesDocumentCollection dc = db.Search(query, null, 0);

I'm wonding if it is some sort of access/permissions issue, but I don't know enough about Notes to correct it.
lotus-error.jpg
0
 

Author Comment

by:marketware
ID: 33739467
I updated the code based on Kris's comments:  The code now looks like this and it blows up with the same message as before on db.Open();

          Domino.NotesSession session = new Domino.NotesSession();
            session.Initialize("");

            NotesDatabase db = session.GetDatabase("", "mail\bbartel.nsf", false);
            db.Open();

Can you download an eval of the domino server?  If so, can you install it on Windows 7 or Vista (I don't have a real server here to install it on)?

bob
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 334 total points
ID: 33741627
Can you check, after each call, that the resulting value isn't null? I suppose there is indeed a session but db may be null.

Did you try the other two ways to create a NotesSession? See this document for an explanation:
http://www.experts-exchange.com/Q_21056925.html

And an interesting approach:
http://www.experts-exchange.com/Q_24180643.html
0
 

Author Comment

by:marketware
ID: 33743614
I think the last comment made some progress.  I've added the following code and I have an error that could be trapped in a try/catch.

            try
            {
                Domino.NotesSession session = new Domino.NotesSession();
                session.Initialize("");
                string server = session.GetEnvironmentString("MailServer", true);
                string maildbname = session.GetEnvironmentString("MailFile", true);
                string username = session.UserName;

                //"mail\bbartel.nsf"
                NotesDatabase db = session.GetDatabase(server,maildbname, false);
                if (db == null)
                    return;
                if (!db.IsOpen)
                    db.Open();

            }
            catch (SystemException ex)
            {
                bc.OKMessage(ex.Message);
            }
error-2.jpg
0
 

Author Comment

by:marketware
ID: 33743637
The error was triggered on this line of code:

NotesDatabase db = session.GetDatabase(server,maildbname, false);
0
 
LVL 16

Expert Comment

by:kris_per
ID: 33743706

Should you pass password in -> session.Initialize("") ?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:marketware
ID: 33743768
Realizing that security is the problem.  I opened the Notes Client and attempted to review the security.  On the file menu I selected Application and Composite Access Control and I got this message.

I don't know enough about Notes to correct the problem.  I didn't originally have Domino installed when I installed Notes and wonder if I should uninstall notes and try to reinstall.
error3.jpg
0
 

Author Comment

by:marketware
ID: 33743775
Kris,

I cleared the password to simplify development.
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 33743890
What happens if you try [File] > [Application] -> [Access Control...]?

I never even noticed the new [Composite Access Control] item.  Not really sure how it differs from the standard ACL.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 33743957
I suppose it's only for Composite Applications.
0
 
LVL 16

Assisted Solution

by:kris_per
kris_per earned 166 total points
ID: 33744148

Can you check if opening a database locally (without any server reference) works or not, like:

NotesDatabase db = session.GetDatabase("",@"c:\notes\data\mail8.ntf", false);

// pass empty string for server name param and
// replace 'c:\notes\data' by your local notes data folder path which will be typically inside the notes installation path.

This is just for testing to see if atleast opening any db works at all....

0
 

Author Comment

by:marketware
ID: 33744696
I uninstalled and reinstalled Notes and I can now get into Access Control List.  I guess I'm going to have to spend some time learning more about Notes Security before I can do anything.

Kris, When I leave the server blank, it returns a null for db.
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 334 total points
ID: 33749384
Try

NotesDatabase db = session.GetDatabase("","mail\\bbartel.nsf", false);

Watch out with the single backskash in strings.
0
 

Author Comment

by:marketware
ID: 33749854
It's always the simple things that kill us!!  

I'll get back for any additional help on this project, but for now this is a solution to getting a connection.
0
 

Author Closing Comment

by:marketware
ID: 33749886
I am now able to make a connection to the database.  The trick was both the way I attempted to connect and the fact that I had not used \\ in the string defining the file name.  Thank you all for your help!!

bob
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.NET Error 7 42
Refresh Datagridview from another form 1 28
comparing string in C# 3 33
Achieve json result 2 32
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now