ProfilePictureEventHandler


Description

A SharePoint Library event handler to automatically link a picture to a MOSS 2007 User Profile.

The file names must be of the following format: [accountName].[ext]

ItemAdded
  • The event handler extracts the account name from the new file
  • The Profile Picture URL property of the corresponding User Profile is updated
  • In case of an error an entry will be written to the machine's event log
ItemUpdating
  • The event handler does not allow a file to be renamed
ItemDeleting
  • The event handler resets the Profile Picture URL property of the correspondingg User Profile
  • In case of an error no additional actions are undertaken (just the file deletion)

Screenshot

Requirements

This event handler uses User Profiles and thus requires MOSS 2007.

Downloads

Visual Studio 2005 Project + compiled assembly

Instructions

Installation:

  • deploy to GAC

Register this event handler for a SharePoint Library (Document Library, Picture Library, ...) or Content type using the SharePoint Object Model, my EventHandlerManager or any other tool.

Feel free to modify and improve this project.

Additional notes

The original version of this Event Handler included additional checks in the ItemAdding event returning an informational message to the user. However my experience of synchronous event handling (and UI messages) in combination with a Picture Library haven't been very good: WSS 3.0 Event Handler- pre-event cancelling issues, so I have omitted that functionality.

 
  • Categories:


Comments

Thursday, 27 Dec 2007 07:53 by Jason
Please can you let me know how this is installed and configured. I am new to moss 2007 and I am struggling to understand how this works.

Thursday, 27 Dec 2007 07:53 by Steven Van de Craen
Hi Jason, it might be a bit cryptic but you have to drag the assembly (.dll) to the GAC (Global Assembly Cache, c:\windows\assembly). Next you can use my tool (see post for link) or another 'event handler registration' tool to activate the event handler for a particular Library. Steven

Thursday, 27 Dec 2007 07:53 by Jason
Copied the file into the GAC and then ran your event handler registartion tool from the root drive. Created a new picture library on my SSP called employee pictures but they do not seem to be apperaing in the user profile. Do you have any ideas. Thanks

Thursday, 27 Dec 2007 07:53 by Jason
Error in Event log Error loading and running event receiver Vandest.ProfilePictureEventHandler in ProfilePictureEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4f658f603c9b5170. Additional information is below. : Requested registry access is not allowed. For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Thursday, 27 Dec 2007 07:53 by Steven Van de Craen
The Event Handler uses the Event Viewer to log error messages. The SharePoint System Account probably doesn't have access to the server's Event Viewer. You can modify the Event Logging code or you can give the System Account the correct permissions.

Thursday, 27 Dec 2007 07:53 by Jason
You have confused me and my server guys here with your last comment as the error we supplied came from the servers event viewer. We cannot understand why the pictures are not appearing in the user profiles. I there any more info I can give you that would help?

Thursday, 27 Dec 2007 07:53 by Steven Van de Craen
Jason, can you give me the event id and source of the event log error ? The event handler might be wanting to log the error but has insufficiënt permissions, thus a permission error is logged by WF, .NET or SharePoint. Please contact me using the Contact Form for additional support.

Wednesday, 16 Jan 2008 02:28 by Grant
We have same issue as the user above the event id is 6875

Friday, 18 Jan 2008 05:03 by Steven Van de Craen

Please make sure the identity for the SharePoint Application Pool has sufficient permissions to write to the Event Log.
* Make the identity a Local Administrator
or
* Grant permissions as follows:
- Start > Run > Regedit
- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog
- Right click on "Eventlog" > Permissions
- Add the SharePoint AppPool identity with Full Control to the list


Tuesday, 29 Jan 2008 08:11 by Nados
Hey there, What would be good would be to auto resize as well off the Handler. This way I dont have to placed JS in the page to resize the big head issue in Search and profile pages. :-)

Thursday, 27 Mar 2008 12:28 by David
Hi, sorry my english, i'm spanish. How resolve you the problem from Jason: Error in Event log Error loading and running event receiver Vandest.ProfilePictureEventHandler in ProfilePictureEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4f658f603c9b5170 I have the same problem. thk all

Friday, 13 Jun 2008 10:00 by B@rney
Hi! I had some trouble getting this to work, but solved by granting Manage User Profiles in SSP to the App Pool Account. Read more here: http://sharepointdemo.biz/blogs/bjarne/archive/2008/06/13/user-profile-picture-library.aspx

Tuesday, 24 Jun 2008 11:25 by ExTrEmE
How to name the file when accountName has a domain? Something like "MyDomain.local\UserId"..

Tuesday, 22 Jul 2008 09:10 by Steven Van de Craen
That's not included i'm afraid. The code would need to be updated to incorporate domain prefixes.

Thursday, 28 Aug 2008 05:40 by enzo
erm is there any way i can upload a description to the sharepoint 2007 with a picture via the use of vb.net code that runs on window mobile devices.

Friday, 29 Aug 2008 09:51 by Steven Van de Craen
If you're using SharePoint API for upload (ie SPFile) you can use a Hashtable with fieldname and value in the Add method.

Saturday, 19 Sep 2009 02:59 by Rüdiger Kerkloh
Steven, I've made some minor changes to support domain accounts (see ExTrÉmeE's question above). Filenames then must have the following format [@domain]. Is it OK for you, sending the code to users asking for it in your blog?

Monday, 21 Sep 2009 09:13 by Steven Van de Craen
Rüdiger, nice work. it's good to see this kind of community feedback. Send me a link or the code itself and I'll update the original post. Regards, S

Thursday, 24 Sep 2009 10:27 by Rüdiger Kerkloh
Thank you, Steven. I have uploaded the changes to http://www.kerkloh.de/download/download.zip

Wednesday, 3 Feb 2010 02:55 by Bhavesha
Hi Steven, The Event Handler was working perfectly as expected. It has stopped working suddnely and is taking the picture from default location and not from the location i am specifying in EventManager.xml Can u pls guide me how do i correct it or how to solve the same as it was working before. Thanks & Regards Bhavesha

Tuesday, 23 Mar 2010 03:16 by Subhadip Goswami
Hi Steven, I've got a problem with my Sharepoint Event Handler, I have created a simple handler for ItemUpdated event, and did the necessery steps for activating the Features, it is working fine for local Users as well as Adiminitrator Account, but the thing is not working while a domain user acess it, No Event is received. Where I am wrong? 1. Related to any pemission Issue? 2. Any Perticular setup for domain users? Please reply me ASAP..

Thursday, 9 Sep 2010 10:35 by online statistics help
Hi Steven, I've got a problem with my Sharepoint Event Handler, I have created a simple handler for ItemUpdated event, and did the necessery steps for activating the Features, it is working fine for local Users as well as Adiminitrator Account, but the thing is not working while a domain user acess it, No Event is received. Where I am wrong? 1. Related to any pemission Issue? 2. Any Perticular setup for domain users? Please reply me ASAP..

Monday, 13 Sep 2010 05:31 by Steven Van de Craen
Hi, Event Handlers trigger for everyone if set up correctly, else they trigger for noone. Try to write logging info as the first entry in your code to see if that works. There is no specific setup for domain users required. It could be that you run into an exception and that you just catch that without logging anything.

Tuesday, 19 Jul 2011 05:23 by Josee
Hi Steven, I will soon need to upgrade from MOSS 2007 to SharePoint 2010. Will the component work in 2010? Is it at all necessary or there is something else already built-in?

Tuesday, 26 Jul 2011 11:45 by Steven Van de Craen
Hi Josee, I've quickly tested the component and it will work with SharePoint 2010, even though it is probably making obsolete API calls. Still, it should survive an upgrade. Out of the box the MY host has a library for User Profile Images, but it seems only to be used for storage. See: http://www.bfcnetworks.com/sharepoint-2010-where-do-my-user-profile-photos-go/ It doesn't bind the picture to the profile at upload. Probably a good thing would be to revise my component to conform to the new method of operation...

Tuesday, 26 Jul 2011 11:58 by Steven Van de Craen
Update to previous post: by running a powershell Update-SPProfilePhotoStore it will create the 3 sizes of the bound picture in the MY host, even if the picture was linked from a different library using my component. Not sure if there's any scheduled job that does this on a regular basis or so. Needs investigation. See: http://support.microsoft.com/kb/2394320/en-us

Monday, 26 Aug 2013 11:02 by Jonnydonk
Hi, We have tried to move this event handler to a Sharepoint Enterprise 2010. Have read the KB Steven mentioned but the version of this Sharepoint is newer than the one this article applies to. There is now errors in Windows Logs and the profile-picture is not updated to the one in the picture library

Monday, 26 Aug 2013 11:52 by Steven Van de Craen
Hey Jonnydonk, What errors are you getting (Event Log, ULS log) ?

Monday, 26 Aug 2013 03:48 by Jonnydonk
Hi, Thanks for quick repsons. This is the error: "Error loading and running event receiver Vandest.ProfilePictureEventHandler in ProfilePictureEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4f658f603c9b5170. Additional information is below. : The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security." Hope this helps REgards

Monday, 26 Aug 2013 04:09 by Jonnydonk #2
Following error appears in Event Log, nothing in the ULS User: leed Message: Error fetching user profile StackTrace: at Microsoft.Office.Server.UserProfiles.UserProfileCache.GetUserData(UserProfileManager objManager, Nullable`1 recordId, Guid gAcct, String strAcct, Byte[] bSid, String strEmail, Boolean doNotResolveToMasterAccount) at Microsoft.Office.Server.UserProfiles.UserProfile.RetrieveUser(String strAcct, Guid gAcct, Byte[] bSid, Nullable`1 recordId, Boolean doNotResolveToMasterAccount, Boolean loadFullProfile) at Microsoft.Office.Server.UserProfiles.UserProfile..ctor(UserProfileManager objManager, String strAcct, Boolean doNotResolveToMasterAccount, Boolean forceUserIsSelf, Boolean loadFullProfile) at Microsoft.Office.Server.UserProfiles.UserProfileManager.GetUserProfile(String strAccountName, Boolean doNotResolveToMasterAccount, Boolean loadFullProfile) at Microsoft.Office.Server.UserProfiles.UserProfileManager.GetUserProfile(String strAccountName, Boolean doNotResolveToMasterAccount) at Microsoft.Office.Server.UserProfiles.UserProfileManager.GetUserProfile(String strAccountName) at Vandest.Utilities.ProfilePictureUtility.<>c__DisplayClass1.b__0() at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.b__2() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Vandest.Utilities.ProfilePictureUtility.UpdateUserProfile(String siteUrl, String userName, String fileUrl) at Vandest.ProfilePictureEventHandler.ItemAdded(SPItemEventProperties properties)

Wednesday, 28 Aug 2013 09:52 by Steven Van de Craen
To rule out a permission issue, grant the application pool account explicit permissions on the User Profile Service Application: Central Admin > UPSA > Administrators

Monday, 16 Sep 2013 08:08 by Jonnydonk
Hi, Sorry for not getting back to you in this case. We found the problem. It seems like it was only new users added after we migrated from Sharepoint 2007 to 2010. We noticed that the URL to the user profile wasn't the same for previous users as for the new ones. Domain name is: ac.contoso.local NETBios domain name is: CONTOSO The old and working profiles name format is : CONTOSO\username The new one that did not work was created in format: ac\username So vi hade to enable Wins-name in den User Profile Syncronisation application, remove the connector and recreate it. Removing-the-connector-warning though, this removes ALL profiles!!! The new profiles was created with correct name and the Profile Picture Event Handler works lika charm!

CAPTCHA Image Validation