Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Im currently customising the CoreResultsWebPart and using it to aggregate Blog posts. One of the default fields it returns is the Author field. The author field though, is crawled and displayed as the Display name of the user. Eg:

A users login name is 'mydomain\john.smith'

Their display name is 'John Smith'

Core results returns 'John Smith'.

I need to get the users login name so I can call a custom function in my xsl 'GetUserProfilePicture(string loginName)' to get the user's profile picture to be shown alongside their blog post summary.

This is the xml output from the search result...

<all_results>
  <result>
<id>3</id>
<workid>96</workid>
<rank>100000000</rank>
<username></username>
<title>What a great post by sp user 1!</title>
<author_multival>S.P. User 1</author_multival>
<author>S.P. User 1</author>
<size>0</size>
<url>http://myintranet/blog/Lists/Posts/ViewPost.aspx?ID=3</url>
<urlencoded>http%3A%2F%2Fmyintranet%2Fblog%2FLists%2FPosts%2FViewPost%2Easpx%3FID%3D3</urlencoded>
<description></description>
<write>3/15/2013</write>
<sitename>http://myintranet/blog/Lists/Posts</sitename>
<collapsingstatus>0</collapsingstatus>
<hithighlightedsummary>
  Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto <ddd> </ddd>
</hithighlightedsummary>
<hithighlightedproperties>
  <hhtitle>What a great post by sp user 1!</hhtitle>
  <hhurl>http://myintranet/blog/Lists/Posts/ViewPost.aspx?ID=3</hhurl>
</hithighlightedproperties>
<contentclass>STS_ListItem_Posts</contentclass>
<isdocument>False</isdocument>
<picturethumbnailurl></picturethumbnailurl>
<serverredirectedurl></serverredirectedurl>
<fileextension>ASPX</fileextension>
<ows_metadatafacetinfo></ows_metadatafacetinfo>
<popularsocialtags>
  <imageurl imageurldescription="List Item">/_layouts/images/STS_ListItem16.gif</imageurl>
</popularsocialtags>
 </result>
 <totalresults>3</totalresults>
  <numberofresults>3</numberofresults>
</all_results>

As you can see above, the author is showing the display name. Below is the code I want to run...

<xsl:variable name="user" select="author"/>
<img align="absmiddle" src="{customxsl:GetUserProfilePictureURL($user)}" border="0" alt="Blog" />



public string GetUserProfilePictureURL(string username)
    {
        string Url = string.Empty;

        if (!String.IsNullOrEmpty(username))
        {
            if (upm.UserExists(username))
            {
                UserProfile profile = upm.GetUserProfile(username);
                if (profile != null)
                {
                    Url = profile["PictureURL"].Value.ToString();
                }
            }
        }

        if (string.IsNullOrEmpty(Url))
            Url = "/_layouts/images/O14_person_placeHolder_96.png";

        return Url;
    }

Anyone know how I can get the login name of the author? Any magic managed properties?

share|improve this question

1 Answer 1

This article seems to describe a solution for you. It discusses the limitations of the default "Author" managed property, and then shows you how to create your own managed property that should be what you want.

  1. The XML schema for the Core Results Web Part (http://msdn.microsoft.com/en-us/library/ms560074(v=office.12).aspx). NOTE: There are some errors in this MSDN documentation link but there is a community section that lists out the default column in the core results XML

  2. The Author and Created By Managed Metadata Properties

The author field is mapped to a number of fields, including the metadata of an office document. When you create an Office document, there is certain information that office captures as “metadata” in the properties section of that document. The Author information is part of this information.

So essentially follow these steps to get a unique name into the Created By Managed property:

  1. Map the crawled property (Name: 4; Category: Office (aka Office:4) ) to the CreatedBy Managed property

  2. Remove the “ows_created_0×2400e_by” crawled property mapping from the CreatedBy property mapping. This crawled property is a left over from SP 2003 days and is not crawled anymore, except for SP 2003 content.

  3. Select the “Select the first property from the property list”. This will ensure that a unique author value is mapped to the “Created By” property (and multiple values are not returned in this property).

  4. Make sure to select refinement enabled, so that you can replace the default “Author” refinement filter with the “Created By” refinement filter.

  5. Save the CreatedBy Managed property

  6. Clear the content collection

  7. Reset the index

  8. Do a Full Crawl

  9. Run a Search, and you will see that the Created By field now contains the most current “Author” information and does not contain a long list of authors

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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