Using the _api/SP.UserProfiles.PeopleManager I've gathered the information needed to display my user profile image and presence.

pInfo is a variable that contains the property information needed to put a string like the one below together, but I'm having some syntax issues.

pInfo.Email will give me bgates@azurenow.com

I need some assistance getting string my src together so it looks like below:


Here I haven't quite grasped how to put it all together:

src="/_layouts/15/userphoto.aspx?size=M&accountname="' + pInfo.Email + '" + "&" + "'+pInfo.PersonalUrl +'" alt="' + pInfo.AccountName + '"

I have used this code before in SharePoint 2007:

ServerContext CTX = ServerContext.GetContext(this.Site);

UserProfileManager UPM = new UserProfileManager(CTX);

string resultado = "<table><tr><td>Cuenta</td><td>Foto</td><td>Web</td></tr>";

foreach (UserProfile UP in UPM) 

resultado += "<tr><td>" + UP["Accountname"].Value + "</td><td>" + UP["PictureUrl"].Value + "</td><td>" +  UP["PersonalSpace"].Value + "</td></tr>";

  • That looks clean and simple, but I'd like to get what I have to work. – Bitspider Mar 12 '15 at 17:45
  • Could you please paste the value of SRC your code is generating right now? – Juan Pablo Pussacq Laborde Mar 12 '15 at 18:02
  • Original results like this: "azurenowgc.sharepoint.com/_layouts/15/…" – Bitspider Mar 12 '15 at 18:29
  • thanks for the quick response. I will make note of the clean code you provided and test it out. By introducing another variable, I was able to build the necessary string. New Variable Introduced: var myurl = "/_layouts/15/userphoto.aspx?size=M&amp;accountname="+ pInfo.Email +'&url='+ pInfo.PictureUrl; Then, all I had to do was add the new variable like so: src="' + myurl + '" alt="' + pInfo.AccountName + '" /> – Bitspider Mar 12 '15 at 18:32
  • It is solved? Glad to read this :-) – Juan Pablo Pussacq Laborde Mar 12 '15 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.