Lotus Notes复制文档 - 保留折叠和未读

时间:2013-02-08 00:40:10

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

我在C#中构建了一个应用程序,它将文档从源NSF复制到目标NSF。目标NSF是一个空壳,保留所有设计元素,基于源NSF。我使用的是Lotus Notes 8.5.3,但未连接到Domino服务器。

我使用此应用程序将源NSF拆分为较小的块。目标是创建可由我们的自动(eDiscovery)系统有效处理的目标NSF。我需要确保保留尽可能多的元数据。

我的现有代码符合这些目标,除此之外 (1)我丢失了文件夹信息。复制文档后,所有文件夹都为空。 (2)所有文件都标记为已读,即使它们在源中未被阅读。

代码C#

//Establish session
NotesSession ns = new Domino.NotesSessionClass();
ns.Initialize("");

//Open source NSF
NotesDatabase nd = ns.GetDatabase("", "test.nsf", false);
//Open destination NSF.
//Assume that all design elements of nd2 are identical to those of nd
NotesDatabase nd2 = ns.GetDatabase("", "test2.nsf", false);

//Create view that returns all documents.
NotesView nView2 = nd.GetView("$All");
nd.CreateView("All-DR", "SELECT @ALL", nView2, false);
NotesView nView = NotesConnectionDatabase.GetView("All-DR");

//Loop through entries in the new view
NotesViewEntry nvec = nView.AllEntries;
nve = nvec.GetFirstEntry();

for (int j = 1; j <= intEntryCount; j++)
{
     if (j == 1)
     {
          nve = nvec.GetFirstEntry();
     }
     else
     {
          nve = nvec.GetNextEntry(nve);
     }

     //Copy document to second database.
     NotesDocument ndoc = nd.GetDocumentByUNID(nve.UniversalID);         
     ndoc.CopyToDatabase(nd2);
 }
 //End loop.
 //All documents are copied.

结果是我最终得到了一个目标NSF,它复制了所有文件。假设所有文件夹也在那里。但是,文件夹中没有任何文件。每个文档都标记为已读。

如何修复文件夹和未读问题?

2 个答案:

答案 0 :(得分:5)

后端类的NotesDocument类中有一个FolderReferences属性。我不是100%确定该属性是否在COM类中公开并且是C#的interop,但如果是,则可以将其与PutInFolder()方法一起使用来解决部分问题。

就读/未读标记而言,关键问题是您是否只关心自己的读/未读状态,或者您是否正在尝试为数据库的所有用户保留它。如果您只关心自己的未读标记,那么您可以使用getAllUnreadDocuments()类的NotesDatabase方法 - 但这需要Notes / Domino 8或更高版本(在您的代码所在的机器上)正在运行),我不确定这个方法(或它返回的NotesNoteCollection类)是否通过C#的COM / interop接口公开。如果可用,则可以遍历集合并使用MarkUnread()方法。如果您关心所有用户的未读标记,那么我不确定是否有办法完成 - 但如果有,则需要使用来自Notes C API的调用。

答案 1 :(得分:2)

关于移动到文件夹的另一个想法,特别是如果数据库没有设置为FolderReferences工作:

您可以迭代从NotesDatabase对象的Views属性获取的NotesView对象数组。每个NotesView都有一个属性,告诉您它是否是一个文件夹。

了解所有文件夹后,您可以在每个文件夹中进行迭代,并收集其中包含的NotesDocuments列表。然后,通过将此信息存储在字典中,您可以将其用作查找,同时处理每个文档以确定需要放置哪些文件夹。

像这样(未经测试):

object oViews = nd.Views;
object[] oarrViews = (object[])oViews;
Dictionary<string, List<string>> folderDict = new Dictionary<string, List<string>>();
for (int x=0; x < oarrViews.Length - 1; x++)
{
    NotesView view = viewArray[x];
    if (view.IsFolder) 
    {
        NotesDocument doc = view.GetFirstDocument();
        while (doc != null)
        {
            // Populate folderDict Dictionary by setting
            // document's UNID as Key, and adding folder name to List
        }
    }
}

然后在你的循环中:

//Copy document to second database.
NotesDocument ndoc = nd.GetDocumentByUNID(nve.UniversalID);  
NotesDocument newDoc = ndoc.CopyToDatabase(nd2);

if (folderDict.ContainsKey(nve.UniversalID)) {
    foreach (var folderName in folderDict[nve.UniversalID]) {
        newDoc.PutInFolder(folderName, true);
    }
}