locked
Obtain user profile image using soap web service RRS feed

  • Question

  • Hi

    I'm trying to retrieve an image of a user that's set in a list. The format of the list column is Person or Group (Name with Picture). Using CSOM javascript I can retrieve the Name (not user name). Anyhow I have two options to obtain the image, it could be sourced from the hidden list in Site collection or from the ups. I'm trying the latter with the code below, but cannot parse the output for the image. The code renders the output on the page without any formatting. If a tree format was available it would help to see how to get to the picture url (I think its PictureURLPublic)

    Any view and help appreciated.

       $(document).ready(function() {
            var soapEnv =
                "<?xml version='1.0' encoding='utf-8'?> \
        <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
      <soap:Body> \
        <GetUserProfileByName xmlns='http://microsoft.com/webservices/SharePointPortalServer/UserProfileService'> \
          <AccountName>wl_dom1\\rajch</AccountName> \
        </GetUserProfileByName> \
      </soap:Body> \
    </soap:Envelope>";
     
            $.ajax({
                url: "http://share.lifecapnet.com/_vti_bin/userprofileservice.asmx",
                type: "POST",
                dataType: "xml",
                data: soapEnv,
                complete: processResult,
                contentType: "text/xml; charset=\"utf-8\""
            });
        });
     
       function processResult(xData, status) {
             var newResults = $(xData.responseXML);
     $("#UPSTest").replaceWith('<div id="UPSTest">' + newResults.text() + '</div>');
     
     
     
     
     
     // the result is burried in XML markup so we look for the right node
     $(xData.responseXML).find('Values').each(function()  
     {  
     // get the text property of the node and display it
     var name = $(this).find('Value').text(); 
     // alert(name); 
     }); 
    
    
    
             
    }
    

    Thursday, January 19, 2017 11:22 AM

All replies

  • Hi orange juice jones,

    We could use the following SOAP message to retrieve the User Profile Property value for specific SharePoint user. To get the URL of the user’s picture, we should use “PictureURL” property name.

       xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
    
       + '<soap:Body>'
    
       + ' <GetUserPropertyByAccountName xmlns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService">'
    
       + '  <accountName>' + accountName + '</accountName>'
    
       + '  <propertyName>' + propertyName + '</propertyName>'
    
       + ' </GetUserPropertyByAccountName>'
    
       + ' </soap:Body>'
    
       + '</soap:Envelope>'


    A demo about how to retrieve SharePoint User Profile Property value with JQuery:

    http://www.sharemuch.com/2012/05/11/retrieve-sharepoint-user-profile-property-value-with-jquery/

    Then we should use <img> HTML tag with “src” attribute to display this image.

    For example:

    var name = $(this).find('Value').text();
    
    document.getElementById("UPSTest").innerHTML="<img src='" + name + "'>";


    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Proposed as answer by Victoria Xia Tuesday, February 7, 2017 5:33 AM
    Friday, January 20, 2017 7:07 AM
  • Hi

    How do I target the correct branch in the soap output ? I'm currently retrieving a jumble of large data.

    var name = $(this).find('Value').text(); In this line name variable contains the entire data, need to pinpoint

    'PictureURLPublichttp://my.lilondon.com:80/User%20Photos/Profile%20Pictures/wl_dom1_raych_MThumb.jpg'

    Friday, January 20, 2017 3:00 PM
  • Hi orange juice jones,

    You could use some JavaScript methods to extracts the characters from a string and get the new sub string.

    For example, we could use split() method to split a string into an array of substrings and returns the new array. Or use the substring() method extracts the characters from a string, between two specified indices, and returns the new sub string.

    Information about JavaScript String substring() method:

    http://www.w3schools.com/jsref/jsref_substring.asp

    Information about JavaScript split() method:

    http://www.w3schools.com/jsref/jsref_split.asp

    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, January 23, 2017 1:57 AM
  • Hi

    Thanks for your help. I would have thought there would be a better way to target the node (PictureURLPublic)?

    Thanks again

    Tuesday, January 24, 2017 10:01 AM
  • Hi orange juice jones,

    Per my testing result, it will get the value of the property without the property name.

    Please check the value in this PictureURLPublic property.

    And you could debug the script to see what is wrong in the script.

    Best regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, February 1, 2017 2:07 AM