Mark said:
We are developing an Intranet using Sharepoint Portal
Server, and my developers are wanting to pull a picture
of every employee from AD. From my reading I have found
that we need to somehow enable the thumbnailPhoto
attribute in AD, but I can't find any detailed
instructions on how to do this.
Any ideas out there?
Mark, from c#, you could do this:
To store the picture:
using System;
using System.DirectoryServices;
using System.Collections;
using System.IO;
public class test
{
public static void Main(String[] args)
{
try
{
DirectoryEntry objDirEnt=new
DirectoryEntry("LDAP://cn=username,cn=users,DC=domain, DC=com");
objDirEnt.Username = "xxx";
objDirEnt.Password = "yyy";
// Force authentication
Object obj = objDirEnt.NativeObject;
FileStream fs = new FileStream("c:\\picture.jpg", FileMode.Open);
BinaryReader r = new BinaryReader(fs);
r.BaseStream.Seek(0,SeekOrigin.Begin);
byte[] ba = new byte[r.BaseStream.Length];
ba = r.ReadBytes((int)r.BaseStream.Length);
objDirEnt.Properties["thumbnailPhoto"].Insert(0,ba);
objDirEnt.CommitChanges();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
return;
}
}
}
To get the picture just do the opposite:
using System;
using System.DirectoryServices;
using System.Collections;
using System.IO;
public class ADRead
{
public static void Main(String[] args)
{
try
{
DirectoryEntry objDirEnt=new
DirectoryEntry("LDAP://cn=username,cn=users,DC=domain, DC=com");
objDirEnt.Username = "xxx";
objDirEnt.Password = "yyy";
// Force authentication
Object obj = objDirEnt.NativeObject;
FileStream fs = new FileStream("c:\\picture2.jpg",
FileMode.Create);
BinaryWriter wr = new BinaryWriter(fs);
byte[] bb = (byte[])objDirEnt.Properties["thumbnailPhoto"][0];
wr.Write(bb);
wr.Close();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
return;
}
}
}
Good luck!
Ryan