Setting up a Lotus Notes Development Environment for C#

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
marketwareAsked:
Who is Participating?
 
Sjef BosmanGroupware ConsultantCommented:
Try

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

Watch out with the single backskash in strings.
0
 
Bill-HansonCommented:
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
 
Bill-HansonCommented:
Also, have you actually launched Notes yet?  You have to run it once to complete setup.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
kris_perCommented:


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
 
marketwareAuthor Commented:
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
 
marketwareAuthor Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
marketwareAuthor Commented:
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
 
marketwareAuthor Commented:
The error was triggered on this line of code:

NotesDatabase db = session.GetDatabase(server,maildbname, false);
0
 
kris_perCommented:

Should you pass password in -> session.Initialize("") ?
0
 
marketwareAuthor Commented:
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
 
marketwareAuthor Commented:
Kris,

I cleared the password to simplify development.
0
 
Bill-HansonCommented:
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
 
Sjef BosmanGroupware ConsultantCommented:
I suppose it's only for Composite Applications.
0
 
kris_perCommented:

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
 
marketwareAuthor Commented:
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
 
marketwareAuthor Commented:
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
 
marketwareAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.