Lotus Domino API - Parsing through NotesItems I have an application that opens a bunch of .nsf databases (73 for now, and that might increase in the future), reads the documents, and reads the items of these documents. Based on the item name, I get the item value to populate a list of custom objects (the pdbdoc you will see below).

Currently, my code is like this:

NotesDatabase notedb = notesSession.GetDatabase(myrootpath, myDBfilename);
NotesDocumentCollection notesColl = notedb.AllDocuments;
if (notesColl.Count &gt; 0)
{
    NotesDocument doc = notesColl.GetFirstDocument();
    try
    {
        while (doc != null)
        {
            if (doc.Items != null)
            {
                foreach (Domino.NotesItem item in doc.Items)
                {
                    if (item.Values != null)
                    {
                        switch (item.Name)
                        {
                            //PDB DATA
                            case "DocArea": pdbdoc.DocArea = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocDisc": pdbdoc.DocDisc = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocObject": pdbdoc.DocObject = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocOrigin": pdbdoc.DocOrigin = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocRef": pdbdoc.DocRef = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocRefClient": pdbdoc.DocRefClient = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocRevDt": pdbdoc.DocRevDt = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocRevNo": pdbdoc.DocRevNo = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocTitle": pdbdoc.DocTitle = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocUnit": pdbdoc.DocUnit = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "INCABINET": pdbdoc.InCabinet = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            //VDB DATA
                            case "VendorDocNm": pdbdoc.DocTitle = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "VendorDocRef": pdbdoc.DocRefClient = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "VendorDocRevNo": pdbdoc.DocRevNo = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "DocUse": pdbdoc.DocObject = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "VendorDocRevDt": pdbdoc.DocRevDt = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "VendorDocClientRef": pdbdoc.DocRef = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                            case "VendorNm": pdbdoc.VendorName = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
                        }
                    }
                }
            }
            doc = notesColl.GetNextDocument(doc);
        }
    }
    catch (Exception ex)
    {
        //Exception handling
    }
}


I think you can spot my question: is there a cleaner and faster way to parse though NotesItems? I don't know the count of documents I read, but it must be around 700.000, each of them with approx. 140 items, that makes around 100.000.000 items to read. That takes some times..

I tried to use doc.GetItemValue(string itemname), but unfortunately, those databases store various kind of documents, and I am only interested in some of them. GetItemValue would require me to first check of the item exists, and then get its value, so basically, that would read twice the items.

Do any of you have another way to parse thought Lotus documents items?
You can rewrite the nested ifs and loops with a nice and short LINQ query that will give you all the items first:

var items
    from doc in notedb.AllDocuments.Where(doc =&gt; doc.Items != null)
    from item in doc.Items.Where(item =&gt; item.Values != null)
    select item;


Then, you loop over the items with a foreach loop:

foreach (var item in items)
{
    SetDocProperty(pdbdoc, item);
}


and call a new helper method that encapsulates the switch:

void SetDocProperty(SomeType pdbdoc, SomeOtherType item)
{
    switch (item.Name)
    {
        //PDB DATA
        case "DocArea": pdbdoc.DocArea = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocDisc": pdbdoc.DocDisc = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocObject": pdbdoc.DocObject = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocOrigin": pdbdoc.DocOrigin = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocRef": pdbdoc.DocRef = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocRefClient": pdbdoc.DocRefClient = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocRevDt": pdbdoc.DocRevDt = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocRevNo": pdbdoc.DocRevNo = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocTitle": pdbdoc.DocTitle = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocUnit": pdbdoc.DocUnit = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "INCABINET": pdbdoc.InCabinet = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        //VDB DATA
        case "VendorDocNm": pdbdoc.DocTitle = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "VendorDocRef": pdbdoc.DocRefClient = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "VendorDocRevNo": pdbdoc.DocRevNo = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "DocUse": pdbdoc.DocObject = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "VendorDocRevDt": pdbdoc.DocRevDt = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "VendorDocClientRef": pdbdoc.DocRef = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
        case "VendorNm": pdbdoc.VendorName = LotusUtils.LotusUtils.LotusItemToString(item.Values); break;
    }
}


You could probably parallelize it with Parallel.ForEach but the code isn't complete so I cannot make any other suggestions as I don't know how the pdbdoc works and what it is.