The dirty world of SharePoint programming

Sometimes SharePoint drives you mad. Case of today:

When you add a QuickLink to a person in SharePoint portal server you get a link to the /mysite/public.aspx page with on the URL in most cases an accountname parameter, so for example http://server/mysite/public.aspx?accountname=DOMAIN%5cusername. There are also situations where instead of an accountname parameter we got the parameter sid. No problem: convert the SID to accountname, done! Not. This SID is not a standard Windows SID. But the public.aspx page knows how to find the profile for this person... If you disassemble the (obfuscated) code that converts a sid to a usable profile object you see that a LOT of shit happens... to much to reproduce in your own code. But there is a dirty solution to retrieve any property from a user it's profile, while providing any of the following options on the URL:

accountname=....
guid=...
sid=...
preferredname=...

Make a page: GetProfileProperty.aspx

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<SPSWC:ProfilePropertyLoader runat="server" />
<SPSWC:ProfilePropertyValue PropertyName="AccountName" ApplyFormatting="false" runat="server" />

Call it like GetProfileProperty.aspx?accountname=domain\user

In the sample code the AccountName is returned, but you can use any property name, or even make the property itself a parameter.

In your code you have to execute a call to the page using the WebRequest class. The result is the property value in plain text.It is an extra roundtrip, but sometimes you don't have many alternatives...

5 Comments

  • Serge,

    It is a great article which will help me with something else (understand person.aspx). Thanks for sharing.

  • Hi Serge,

    Thanks a lot for this article. It helps me big time with my branding problems. . . :-D

  • Wow, I hope I don't have to do this. But thanks for the info.

  • Hi Serge, Thanks for the info. How would I get the result into a javascript variable?

  • Hi Serge,

    I have a requirement to display the property value as a search keyword link, the way it displays OOB. I too am using ProfilePropertyValue to display the value of the property but am unable to add a link to it which when clicked will search for that property's value in the search center site. I want to do this for both single and multi-valued properties.

    Any help is highly appreciated.

    Thanks,
    Neha

Comments have been disabled for this content.