Problem creating contact using Domino Objects

Hi there!. I’m trying to build a small application to create contacts, and todo’s records, using the domino objects, but obviously I’m doing something wrong, because the code is not working.

My Setup:

Lotus Notes 8.5, using a local database only, no server.

C# and Visual Studio 2005/SP2

Here is my code (seems to be fine?):

bool result = false;

Session oNotesSession= new Session();

Domino.NotesDatabase database = null;

Domino.NotesDocument mydoc = null;

oNotesSession.Initialize(“”);

oNotesDatabase = oNotesSession.GetDatabase(“”, “names.nsf”,false);

if (!database .IsOpen)

{

database.Open();

}

database = oNotesSession.OpenNotesSession();

mydoc = database.CreateDocument();

mydoc.AppendItemValue(“FirstName”, “Jhon”);

mydoc.AppendItemValue(“LastName”, “Doe”);

mydoc.PutInFolder(“Contacts”,false);

result = mydoc.Save(true, false, false);

Running the code step by step, I noticed the following exception on mydoc object, under FolderReferences:

‘((Domino.NotesDocumentClass)(mydoc)).FolderReferences’ threw an exception of type ‘System.Runtime.InteropServices.COMException’

detail: {“Folder References are not enabled on the database”}

I tried to enable the FolderReferencesEnabled flag on the database object, but the code crash (Notes closes abruptly), probably “names.nsf” doesn’t allow FolderReferencesEnabled. Please help, and excuse me if this is a newbie error.

Thanks,

Aaron

Subject: Shouldn’t need the PutInFolder

I think what you want is to add the Form value of “Person” and then save it. That should get your new contact displayed in the Contacts view.

mydoc = database.CreateDocument();

mydoc.AppendItemValue(“FirstName”, “Jhon”);

mydoc.AppendItemValue(“LastName”, “Doe”);

mydoc.AppendItemValue(“Form”, “Person”);

result = mydoc.Save(true, false, false);

Subject: Updated c# code with suggestion

Hi Ted, thanks a lot for your help. In addition to your suggestion, I included the “Type” value, and now it works (is not working without the Type vale…) Here is the updated c# code:

bool result = false;

Domino.NotesSession oNotesSession = new Domino.NotesSession();

Domino.NotesDatabase oNotesDatabase = null;

Domino.NotesDocument mydoc = null;

oNotesSession.Initialize(“”);

oNotesDatabase = oNotesSession.GetDatabase(“”, “names.nsf”,false);

//If the database is not already open then open it.

if (!oNotesDatabase.IsOpen)

{

oNotesDatabase.Open();

}

mydoc = oNotesDatabase.CreateDocument();

oNotesDatabase.FolderReferencesEnabled = true;

mydoc.ReplaceItemValue(“FirstName”, “Jhon”);

mydoc.ReplaceItemValue(“LastName”, “Doe”);

mydoc.ReplaceItemValue(“Form”, “Person”);

mydoc.ReplaceItemValue(“Type”, “Person”);

result = mydoc.Save(true, false, false);

Regards,

Aaron