[/code]"> [/code]"> [/code]">
[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