using the thumbnailPhoto attribute

M

Mark

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?
 
D

Diana Smith [MSFT]

Hello Mark,

Here are some articles that should help you:
292029 HOWTO: Manipulate the ThumbNailPhoto Attribute of a User Object in
the
http://support.microsoft.com/?id=292029


Q290999 INFO: Determine the lDAPDisplayName for an Attribute
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q290999

More Info
=======
There is an attribute thumbNailPhoto which should be large enough to store
most small image files.

If your image is larger, then you may either want to create another
attribute or store the image in a database or file share and maintain a
reference to the location of the image in the attribute.

MSDN provides all the documentation for extending the Users & Computers
snap-in with Property Pages & Context Menus. The sample code that was
included in the SDK in fact extends the snap-in with an additional property
page that exposes both the thumbNailPhoto and employeeID attributes.

I believe these were placed as samples in the Platform SDK. You should be
able to find them under \Microsoft Platform
SDK\Samples\NetDs\ADSI\Samples\DSUI\userext\

Thank You.

Diana
 
R

Ryan Fransen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top