I am reading the image from Active Directory the Property["thumbnailPhoto"].
My Model assigns it to this:
public Image thumbnailPhoto { get; set; }
My Service runs this code to put get the image from Active Directory and put it into my Model.
public Image GetUserPicture(string userName)
{
using (DirectoryEntry de = new DirectoryEntry("LDAP://server.com"))
using (DirectorySearcher ds = new DirectorySearcher(de))
{
ds.Filter = ("(&(objectCategory=person)(objectClass=User)(sAMAccountName=" + userName + "))");
ds.PropertiesToLoad.Add("thumbnailPhoto");
SearchResult rs = ds.FindOne();
using (MemoryStream s = new MemoryStream(rs.Properties["thumbnailPhoto"][0] as byte[]))
{
return Bitmap.FromStream(s);
}
}
}
I call the above method and assign it to the Model from this line:
user.thumbnailPhoto = GetUserPicture(rs.Properties["sAMAccountName"][0].ToString());
This all seems to be working, no errors, I can see in the debugger that user.thumbnailPhoto is of type System.Drawing.Bitmap.
Where I am stuck now is how to display this on a webpage?
Is it possible to throw this thumbnailPhoto
into a Session["UserPhoto"]
since I will need it on every single page?