This post is a contribution from Charls Tom Jacob, an engineer with the SharePoint Developer Support team.
Recently, one of my customers came up with an issue related to user profiles. The problem was for certain users, profile picture wasn’t showing up. Instead the typical red X sign indicating a missing image file was displayed.
On investigating this, we found that user profile images are missing from the picture library that stores profile photos. We verified IIS logs to confirm that HTTP error code 404 (File Not Found) was recorded for requests to load image files.
The solution was to place those missing images back to the library. Fortunately, customer had a repository of all user images and they were ready to restore them back. But the site contained more than 10,000 users. The challenge was to find out how many of those user’s do not have their profile images.
We used the following object model code to list our users that does not have images available in picture library. It uses UserProfileManager class to iterate through all the user profiles and if the profile has PictureUrl attribute set, an HttpRequest is sent to fetch the image. Looking at the HTTP response we get back, the code decides if the image is actually available or not.
Here’s the sample code:
We hope this code sample is of help to you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.