简体   繁体   中英

Picture retrieval from Active Directory c#

在此处输入图片说明

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?

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

What about convert to base64?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM