I had the need of reading from lotus notes specific user information, the solution i had before was traversing whole lotus notes document inside $people view and getting one by one document and comparing if this is the document i need But the problem with that approach was 1) It was not proper of having a loop 2) It was too slow and my web service was getting timed out as it was traversing
There is a better way to do it like following
var session = new NotesSession(); session.Initialize(password); NotesDatabase _serverDatabase = session.GetDatabase(serverName, "names.nsf", false); NotesView _peopleView = _serverDatabase.GetView("$Users"); // Searching using email, if any document matches with this email string NotesDocumentCollection tmpDoc = _peopleView.GetAllDocumentsByKey(userMail, false); // There could be multiple enteries for (int i = 0; i < tmpDoc.Count; i++) { NotesDocument tmpDoc1 = tmpDoc.GetNthDocument(i); // Take full name of a user when firstname+lastname+email matches if (firstName.ToUpper() == Convert.ToString(tmpDoc1.GetItemValue("FirstName")[0]).ToUpper() && lastName.ToUpper() == Convert.ToString(tmpDoc1.GetItemValue("LastName")[0]).ToUpper() && userMail.ToUpper() == Convert.ToString(tmpDoc1.GetItemValue("InternetAddress")[0]).ToUpper()) // Do your thing here }
Above you can see i am loading a view called $Users and trying to getAllDocuments having a key, in my example i am passing an email, but you can have anything there and that key would be searched in whole document, so if you are passing a text which could be in many fields, multiple document would be returned containing those matches in different fields, and you can compare you condition to make sure you get the right document out of those multiple returned documents in this way you can avoid traversing through all the available documents and instead find one, i thought it would be helpful for others hence sharing it ;-)
Comments
Post a Comment