Download photos from Active Directory with Lotusscript

I have created a Lotussscript that makes an LDAP query against Active Directory to get the first name, last name, department, phone, mobile and email for all users within a given department.

For each person I create a Notes document where I save this information. It is then displayed on a web page with HTML formatting.

However, I would also love to have the user photo in this list. In Power Shell I managed to figure out how to get the photo when I created a similar solution a few years back. But I can’t for the life of me figure how to get the photo in Lotusscript. I want to store the photo in a rich text field, and then use it on the web page.

Has anyone done this? I am able to get hold of the photo attribute in the LDAP query. But doing a thumbnailphoto.value, like I do on a field like mobile.value, only returns an error (which I guess is because it’s not a text but a photo).

Any help here would be appreciated

Subject: Possible in Lotusscript?

@Edson: That looks exactly what I’m after, only in Lotusscript Thanks.

I will check the VB code to see if I can “translate” it into LS, I know they are quite similar, but it seems that there is stuff going on here that would not be possible with LS.

Any ideas or tips are appreciated.

Subject: Can’t figure out how to do this in Lotusscript

I’ve been going through the VB -code now, and I understand it.

However, I’m not able to do this via LS. I just don’t understand how to get the file from AD and down to the disk on the server where I’m running the script.

Subject: Please, reply to your post if you still find any issues :slight_smile:

Subject: Sugestion

Here is a dll that I used in the past to “paste” photos into notes documents use lotusscript. Voith's CODE :: Import Image 2 Lotus Notes http://www.vcode.no/web/vcode.nsf/htdocs/ii2ln

Subject: Handle it as a file/attachment

Hello Hogne,

I would suggest you to download the actual photo/picture from Active Directory, if that is possible, then attach it to the Notes document. I think you won’t be able to view the file directly from Active Directory once it would need a HTTP server to actually display it, which you will have in Domino.

HTH. Regards,

Edson Luis Almeida Viana

Subject: Getting hold of the photo

@Barry: Thanks, but getting photos IN to the field is not the problem. My problem is getting hold of the photo and downloading it from AD.

Subject: Trying to download

Hi, Edson.

Thanks for your reply.

Sorry for not being clear about this, but I am actually trying to download it from AD, and then attach it to the Notes/Document. I was hoping this could be done when getting all the other data about the user from AD.

Here’s my code:

Set dbCurrent = s.Currentdatabase
Set objConnection = CreateObject(“ADODB.Connection”)
objConnection.Open “Provider=ADsDSOObject;”
'test = objConnection.DefaultDatabase

Set objCommand = CreateObject(“ADODB.Command”)
Set objCommand.ActiveConnection = objConnection

strLdapFilter = “Select sn, givenName, mail, telephoneNumber, mobile, department, employeeID, manager, thumbNailPhoto, sAMAccountName FROM 'LDAP://ou=” & strDepartment & “,ou=Users and Groups,ou=,dc=,dc=com’ WHERE objectCategory=‘person’ AND objectClass=‘user’”

objCommand.CommandText = strLdapFilter
Set objRecordSet = objCommand.Execute

If objRecordSet.RecordCount = 0 Then
MsgBox “No groups found!”
Else
While Not objRecordset.EOF
Set docPerson = dbCurrent.Createdocument()
docPerson.Form = “frmEmployee”
docPerson.sn= objRecordset.Fields(“sn”).value
docPerson.givenName = objRecordset.Fields(“givenName”).value
docPerson.department = objRecordset.Fields(“department”).value
docPerson.telephonenumber = objRecordset.Fields(“telephoneNumber”).value
docPerson.mobile = objRecordset.Fields(“mobile”).value
docPerson.mail = objRecordset.Fields(“mail”).value

Here is where I’m trying to get hold of the photo, and attach it to the Notes Document:
'Set rtItem = New NotesRichTextItem(docPerson, “thumbNailPhoto”)
'Set object = rtItem.EmbedObject(EMBED_OBJECT, “”, objRecordset.Fields(“thumbNailPhoto”))

The above didn’t work, so I then tried this:

Dim filenum As Integer
Dim filename As String
Dim varPhoto As Variant
Set varPhoto = objRecordset.Fields(“thumbNailPhoto”)
filename = “C:\user_icons\test.jpg” ’ & objRecordset.Fields(“sAMAccountName”).value
filenum% = FreeFile()
Open filename For Binary Access Write As fileNum%
'Put #filenum%, , varPhoto
Put #filenum%, , filenum
Close filenum%
Call docPerson.Save(True,False,True)

objRecordset.MoveNext
Wend

No dice so far. Any ideas? Is it even possible?

Subject: Found something on MS Technet Forum that may help you

Hello Hogne,

This is what I found:

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/1fac22c6-536f-4b4f-a272-79f10642990e/help-stuck-with-vbs-ad-query-that-save-files-from-thumbnailphoto-into-bmp-file-it-doesnt-go-threw?forum=ITCG https://social.technet.microsoft.com/Forums/scriptcenter/en-US/1fac22c6-536f-4b4f-a272-79f10642990e/help-stuck-with-vbs-ad-query-that-save-files-from-thumbnailphoto-into-bmp-file-it-doesnt-go-threw?forum=ITCG

It seems (mainly on the responses to that topic) that downloading the photo is an option. When you have it on a file system, you may attach it to a Notes document using a LotusScript.

I think it would be easier if there was a way to publish the photo directly from AD using HTTP… maybe there is a plugin on IIS that you could use for it. Then I think it would not be so difficult to place the URL to the photo on a Notes document, maybe on a HTML tag.

HTH. Regards,

Edson Luis Almeida Viana