Lotus Notes -以编程方式添加表单- NotesForm

本文关键字:添加 表单 方式 NotesForm 编程 Notes Lotus | 更新日期: 2023-09-27 18:02:09

我想以编程方式从一个NSF复制表单到另一个NSF。我知道NotesDocument类有CopyToDatabase方法,NotesDatabase类有CreateView方法。

然而,我还没有找到任何东西允许我添加一个表单到NSF。

我使用的是Lotus Notes 8.5.2、COM和c#。

检索或删除表单信息没有问题,我有以下代码片段:

        //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);              
        }

Lotus Notes -以编程方式添加表单- NotesForm

使用NotesNoteCollection类,您可以获得表单的集合。将SelectForms属性设置为TRUE,其余属性设置为FALSE

在构建NotesNoteCollection之后,它将包含一个表单(文档)的集合,可以像这样访问:

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

可以使用CopyToDatabase方法复制文档

对于c#用户…

        //NotesConnectionDatabase is of type NotesDatabase.
        //A NotesNoteCollection represents a collection of Domino design 
        //and data elements in a database.
        NotesNoteCollection nnc;
        nnc = NotesConnectionDatabase.CreateNoteCollection(false);
        //All the different types of elements default to false.
        //Set SelectForms = true to add forms to the collection.
        nnc.SelectForms = true;
        nnc.BuildCollection();
        //...
        string nid = nnc.GetFirstNoteId();
        for (int i = 1; i <= nnc.Count; i++)
        {
              NotesDocument doc = NotesConnectionDatabase.GetDocumentByID(nid);
              doc.CopyToDatabase(ndDestination);
              Console.WriteLine(nid + " copied");
              swCopyForms.WriteLine(nid + " copied");
              nid = nnc.GetNextNoteId(nid);
        }