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

时间:2011-07-15 22:38:28

标签: c# com lotus-notes lotus lotus-domino

我想以编程方式将表单从一个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);              
        }

2 个答案:

答案 0 :(得分:2)

使用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方法

复制文档

答案 1 :(得分:0)

对于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);
        }