[Update: Code download files updated 18/03/2011 – see below]
This is in relation to a previous post I made last week;
So, the source code is finally ready and uploaded for your enjoyment 🙂
Now – I must first off give credit to the sources of inspiration. A lot of the code in this solution is copied / borrowed / inspired by the following posts:
- MSDN Blog – Background information on why you cannot import the property from AD directly
- Blog Post – How to upload a user profile photo programmatically
- Technet Blog – Programmatically using the jpegPhoto attribute in Active Directory
All I have done is brought their code and samples together and packaged it into a WSP that runs from SharePoint Timer jobs, so you have the convenience of a SharePoint 2010 farm solution 🙂
Also it should be understood that both AD and the User Profile database are quite critical parts of anyone’s SharePoint farm, so sorry, but first I need to make a ….
… Disclaimer – All code and solutions are provided “as is” and should be used at your own risk! It is highly recommended that you test these in an isolated environment, and I confer no responsibility for any loss or damage from using the code, advice or solutions provided on this blog, or any related content.
Ok, now that is out of the way we can get on with business 🙂
[Update – 18/03/2011 – I have updated both sets of files so that it now uses the “distinguishedName” attribute to identify users in AD .. as this is a more reliable method and was in response to a reported bug]
I have uploaded the files to my Sky Drive including:
When you roll out the WSP you will find that it includes the following functionality:
Farm Scoped Feature
The WSP package includes a farm scoped feature called:
Hatch Solutions – Import Photos from AD (Timer Job)
When activated this will automatically identify the default MySite host application and create a custom Timer Job (see below) attached to that web application.
My Site Timer Job
The Timer Job (installed by the Farm Feature) is designed to run on the My Site Host web application, and is pre-configured to run once-per hour. It is called:
Hatch Solutions – Import Photos from AD
This will do the following:
- Automatically identify all AD accounts in the current User Profile Database
- If the AD account has a “jpegPhoto” attribute, then this is extracted
- The photo is converted to three thumbnail images, and uploaded to the My Site Host profile photo asset library
- The photo for that user profile is updated to point at their newly uploaded photo
Hope you enjoy, the source code is there for all to see, and good luck!