[/code]"> [/code]"> [/code]">
I have created a AD forest that search for a user across all domains in the forest using its global catalog connection string.

I am trying to get thumbnailPhoto of AD user using c# code. But I did not get thumbnailPhoto property in result object even though it exist in AD.

I had verified the thumbnailPhoto prop in AD using powershell. Also I have verified it by getting using LDAP connection string. It both case I got the byte array.

Below is the code to get user and its properties and _configuration.GlobalCatalog returns the Global catalog connections string which is in format (GC://domain-name).
[code]public Task<ProfileImage> GetProfileImageByEmail(string email) { var filterQuery = ("mail=" + email); return Task.FromResult(GetProfileImageFromAD(filterQuery)); } private ProfileImage GetProfileImageFromAD(string filterQuery) { var result = GetADUserDetails(filterQuery); if (result == null) return null; if (result.Properties.Contains("thumbnailPhoto")) { var imageBytes = result.Properties["thumbnailPhoto"][0] as byte[]; if (imageBytes != null) { return new ProfileImage { Content = new MemoryStream(imageBytes), ContentType = "image/jpeg" }; } } return null; } private SearchResult GetADUserDetails(string filterQuery) { using (var userBinding = new DirectoryEntry(_configuration.GlobalCatalog)) { using (DirectorySearcher adSearch = new DirectorySearcher(userBinding)) { adSearch.ReferralChasing = ReferralChasingOption.All; adSearch.Filter = filterQuery; adSearch.PropertiesToLoad.Add("mail"); adSearch.PropertiesToLoad.Add("sn"); adSearch.PropertiesToLoad.Add("givenName"); adSearch.PropertiesToLoad.Add("thumbnailPhoto"); return adSearch.FindOne(); } } }[/code]


JLCPCB – Prototype 10 PCBs for $2 (For Any Color)

China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir