This project has moved and is read-only. For the latest updates, please go here.

How to call Mysite Profile Pictures

Jun 8, 2012 at 6:23 PM

How would you go about calling Profile Picture Url's from other peoples profiles. Like the script used for the current user except by the user id of my choice? 

$().SPServices.SPGetCurrentUser({fieldname: "picture"})

Jun 9, 2012 at 3:41 AM

If you're running MOSS or SharePoint 2010 Server, you'd probably want to use the UserProfileService.

SPGetCurrentUser only gets, well, the current user.


Jun 11, 2012 at 1:08 PM

If the UserProfileService doesn't work for you, this might.  I'm using MOSS 2007 and wanted to extract some information from a specific user's personal page as well--info that I couldn't get through the other available user functions.  I did so by extracting a copy of the Ajax call that Mark makes in the SPServices library and tweaking it a bit in my own code to get to the user I wanted:

function GetSelectedUserInfo(lngUserID){
    async: false,
    // Force parameter forces redirection to a page that displays the information as stored in the UserInfo table rather than My Site.
    // Adding the ID parameter returns the page of the selected user
    // Adding the current date/time parameter forces the server to view this as a new request.
    url: $().SPServices.SPGetCurrentSite() + "/_layouts/userdisp.aspx?Force=True&ID=" + lngUserID + "&" + new Date().getTime(),
    complete: function (xData, Status) {
      // You can extract any of the standard fields here by passing the correct Field Internal Name
      objMyVar = CustomGetUserData(xData.responseText, "Title");

function CustomGetUserData(xData, strFieldName){
  var thisField = "";
  var thisTextValue = RegExp("FieldInternalName=\"" + strFieldName + "\"", "gi");
  $(xData).find(" td[id^='SPField']").each(function() {
    if(thisTextValue.test($(this).html())) {
      // Each fieldtype contains a different data type, as indicated by the id
      switch($(this).attr("id")) {
        case "SPFieldText":
          thisField = $(this).text();
        case "SPFieldNote":
          thisField = $(this).find("div").html();
        case "SPFieldURL":
          thisField = $(this).find("img").attr("src");
        // Just in case
          thisField = $(this).text();
  return (thisField !== undefined) ? thisField.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '') : null;

Now, I haven't actually tried to extract the picture this way but i don't see any reason why it wouldn't work.

Jun 11, 2012 at 2:09 PM

@gkoliver How would you do a call to your script? Sorry Im not very good at javascript yet..

Jun 11, 2012 at 3:45 PM

You'll need something, for instance, a button or another function, that calls "GetSelectedUserInfo(lngUserID)", passing the actual user ID in place of "lngUserID."