3

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1

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

Sully
  • 14,672
  • 5
  • 54
  • 79
  • I am getting the value in the byte array (attached is the image in the question). How can I display it on html page? – Mohammed Tariq May 11 '18 at 08:23
  • Save the image somewhere `Bitmap.FromStream(s).Save(path);`, or manage the response to only respond with images. if you are still having issues, then open a new question as it is unrelated to the original question. – Sully May 11 '18 at 09:45
  • Check this as well https://stackoverflow.com/questions/44054639/storing-an-image-from-a-url-into-a-bitmap-with-memory-stream – Sully May 11 '18 at 09:49
  • Thanks it worked! But the image pixel resolution is not good! :( any way to make it better? – Mohammed Tariq May 11 '18 at 12:21
  • Accept the answer and open a new question, but check this first https://stackoverflow.com/a/42113158/643500 – Sully May 11 '18 at 12:53
1

What about convert to base64?

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

if (buffer != null)
var base64Thumb = Convert.ToBase64String(buffer);
        
Elialber Lopes
  • 633
  • 7
  • 18