Author:水如烟
一般来说,地址本有两个以上,一是本机的地址本,二是服务器的地址本。如果层级公司多,服务器的地址本就有多个。
NotesSession.AddressBooks可以取到所有地址本。
Session在正常登录后,如本机没有联接服务器,AddressBooks为空;如联接上服务器,AddressBooks才取到服务器地址本的数据库。
如果对用户名(包括群组名)有兴趣,那么,可以将所有地址本的用户(包括群组)最基本的信息导出来,存放到本地一个xml文件中去。
在一个ds数据集中建立一个Names表,包括以下列:
列名 | 类型 | 作用 |
Server | String | 所在服务器名称 |
DbName | String | 所在数据库名称 |
NoteID | String | 在数据库中的NoteID值 |
Name | String | 用户或群组名称 |
IsPerson | Boolean | Ture是用户,False是群组 |
NoteID的作用是:在需要更新用户信息时,通过NoteID可以迅速定位到相应的NotesDocument。如:
Public Shared Function GetDocument(ByVal session As NotesSession, ByVal row As ds.NamesRow) As NotesDocument Dim server As String = row.Server If server = "Local" Then server = Nothing Dim db As NotesDatabase = session.GetDatabase(server, row.dbName, False) Return GetDocument(db, row) End Function Public Shared Function GetDocument(ByVal db As NotesDatabase, ByVal row As ds.NamesRow) As NotesDocument Return db.GetDocumentByID(row.NoteID) End Function
导出数据代码:
Namespace LzmTW.Lotus.Framework Public Class Names Private Const Local As String = "Local" Private gDataset As New ds Public ReadOnly Property DataSet() As ds Get Return gDataset End Get End Property Private ReadOnly Property table() As ds.NamesDataTable Get Return Me.DataSet.Names End Get End Property Public Sub ReadXml(ByVal file As String) Me.DataSet.ReadXml(file, XmlReadMode.ReadSchema) End Sub Public Sub WriteXml(ByVal file As String) Me.DataSet.WriteXml(file, XmlWriteMode.WriteSchema) End Sub Public Sub AddItem(ByVal nameTable As ds.NamesDataTable, ByVal server As String, ByVal dbName As String, ByVal name As String, ByVal noteID As String, ByVal IsPerson As Boolean) If String.IsNullOrEmpty(server) Then server = Local End If Dim row As ds.NamesRow = nameTable.FindByServerdbNameNoteID(server, dbName, noteID) If row Is Nothing Then nameTable.AddNamesRow(server, dbName, noteID, name, IsPerson) Else row.Name = name row.IsPerson = IsPerson End If End Sub Public Sub AddItem(ByVal server As String, ByVal dbName As String, ByVal name As String, ByVal noteID As String, ByVal IsPerson As Boolean) Me.AddItem(Me.table, server, dbName, name, noteID, IsPerson) End Sub Private cacheDateset As ds Private cacheServer As String Private cacheDbname As String Public Sub AddFromDatabase(ByVal db As NotesDatabase) Me.cacheDateset = New ds Me.cacheServer = db.Server If String.IsNullOrEmpty(Me.cacheServer) Then Me.cacheServer = Local Me.cacheDbname = db.FileName Dim view As NotesView = db.GetView("$VIMPeopleAndGroups") Dim ec As NotesViewEntryCollection = view.AllEntries ec.ForEachViewEntry(AddressOf AddItemFormCache) Me.DataSet.Merge(Me.cacheDateset, False) Me.cacheDateset.Dispose() Me.cacheDateset = Nothing ec.Dispose() view.Dispose() End Sub Private Sub AddItemFormCache(ByVal entry As NotesViewEntry) Dim dc As NotesDocument = entry.Document Dim noteID As String = dc.NoteID If dc.HasItem("Type") Then Dim type As String = dc.GetItemValue("Type").ToString If type = "Group" Then Me.AddItem(Me.cacheDateset.Names, Me.cacheServer, Me.cacheDbname, dc.GetItemValue("ListName").ToString, noteID, False) ElseIf type = "Person" Then Me.AddItem(Me.cacheDateset.Names, Me.cacheServer, Me.cacheDbname, dc.GetFirstItem("FullName").Values(0).ToString, noteID, True) End If End If End Sub Public Shared Function GetDocument(ByVal session As NotesSession, ByVal row As ds.NamesRow) As NotesDocument Dim server As String = row.Server If server = Local Then server = Nothing Dim db As NotesDatabase = session.GetDatabase(server, row.dbName, False) Return GetDocument(db, row) End Function Public Shared Function GetDocument(ByVal db As NotesDatabase, ByVal row As ds.NamesRow) As NotesDocument Return db.GetDocumentByID(row.NoteID) End Function End Class End Namespace
说明:因地址本数据库结构不同,代码中的取值方法可能不一样。这需要自己分析。
在我的实际中,所有地址本都有个$VIMPeopleAndGroups视图,从中可以得到我关心的内容。