Thursday, September 25, 2008

get user name from id file

Lets think, if you should receive a name from user.id. Which approach did you choose? I made it using next function. Would be great if somebody share another approach. I think it is possible to use Notes API approach...

Dim s As New NotesSession
Dim stream As NotesStream

Dim body As Variant
Dim pathname As String
Dim strBody As String

pathname = "c:\user.id"

Set stream = s.CreateStream

If Not stream.Open(pathname, "ASCII") Then
Messagebox pathname,, "Open failed"
Exit Sub
End If
If stream.Bytes = 0 Then
Messagebox pathname,, "File has no content"
Exit Sub
End If

body = stream.Read(stream.Bytes)
Call stream.Close

Forall x In body
If x <> 0 Then
strBody = strBody & Chr(x)
End If
End Forall

Msgbox Strleft(Strrightback(strBody, "CN="), "/")

2 comments :

Josep Alemany i Fruitós said...

Nice and usefull trick, Pastovenskyi Dmytro

Yuriy Pastovenskyy said...

Brother, you are right about Notes Api, it is pretty easy with C++ Notes Api toolkit (which gives you much more capabilities then direct reading of id-file):

1. LNNotesSession::GetIDFile( const LNString &filepath, LNIDFile *idfile ) const

2. LNIDFile class properties:
GetClassID
GetClientType
GetFilepath
GetUserName
IsCertifier
IsHierarchical
IsNorthAmerican
IsSafe