Mohammed Tariq
Mohammed Tariq

Reputation: 43

Picture retrieval from Active Directory c#

enter image description here

I am particularly new with LDAP and wanted to know if there is a way we could know what information has been filled in the active directory for a particular domain.

For example I am trying to obtain the image of the employees of an organization using

var bytes = directoryEntry.Properties["thumbnailPhoto"].Value;

But this returns null. Now I want to know if the image exists and maybe I am not getting it the right way or there is no image?

Upvotes: 3

Views: 7442

Answers (2)

Elialber Lopes
Elialber Lopes

Reputation: 663

What about convert to base64?

var bytes = directoryEntry.Properties["thumbnailPhoto"].Value;

if (buffer != null)
var base64Thumb = Convert.ToBase64String(buffer);
        

Upvotes: 1

Sully
Sully

Reputation: 14943

Try it this way

var data = user.Properties["thumbnailPhoto"].Value as byte[];

if (data != null)
    using (var s = new MemoryStream(data))
        return Bitmap.FromStream(s);
else
    foreach (PropertyValueCollection p in user.Properties)
        Trace.WriteLine(p.PropertyName);

Double-check the property, it might be jpegPhoto

byte[] data = user.Properties["jpegPhoto"].Value as byte[];

Source:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/02690cfa-c2c1-43d7-9f82-7d210cb86267/c-code-to-add-and-retrieve-user-photos-from-active-directory?forum=csharpgeneral

Upvotes: 1

Related Questions