Search code examples
c#comlotus-noteslotuslotus-domino

Lotus Notes - Add a Form Programmatically - NotesForm


I would like to copy a form from one NSF to another NSF programmatically. I am aware that the NotesDocument class has the CopyToDatabase method, and the NotesDatabase class has the CreateView method.

However, I have not found anything to allow me to add a form to an NSF.

I am using Lotus Notes 8.5.2, COM, and C#.

I have no problem retrieving information about forms or deleting them, and I have the following code snippet:

        //NotesConnectionDatabase and nd2 are objects of type NotesDatabase and are 
        //members of the same session.

        //Write the name of each form to the console.
        //Delete each form from the database.
        for (int i = 0; i <= (((object[])NotesConnectionDatabase.Forms)).Length - 1; i++)
        {
            Console.WriteLine(((NotesForm)((object[])NotesConnectionDatabase.Forms)[i]).Name);
            ((NotesForm)((object[])NotesConnectionDatabase.Forms)[i]).Remove();
        }

        //For each form in nd2, copy the form to NotesConnectionDatabase.
        for (int j = 0; j <= (((object[])nd2.Forms)).Length - 1; j++)
        {
            //I am aware that there is no such method as NotesForm.CopyToDatabase
            ((NotesForm)((object[])nd2.Forms)[j]).CopyToDatabase(NotesConnectionDatabase);              
        }

Solution

  • Using the NotesNoteCollection class you can get a collection of the forms. The SelectForms property should be set to TRUE and the rest should be set to FALSE.

    After building the NotesNoteCollection it will contain a collection of form (documents) that can be accessed like this:

    nid = nc.GetFirstNoteId
      For i = 1 To nc.Count
        Set doc = db.GetDocumentByID(nid)
        nid = nc.GetNextNoteId(nid)id
      Next
    

    The document can be copied with the CopyToDatabase method