SharePoint 2010 Search Result file icon change

2019-05-31 13:45发布

I am trying to change the aspx file icon from default icon to customized icon. I edited the xsl of the results.aspx page "fetched properties" for this section. I wanted to make sure that LegalDoc16.gif icons are displayed for the items who has "LegalDocument" content type. Please let me know if I dont have to syntaxed properly configured. I can do a search like ContentType:"legaldocument" and I get all the documents. so I know contenttype metadata property is being pulled. Please suggest.

  <div class="srch-Icon" id="{concat($currentId,'_Icon')}"> 
    <xsl:choose>
        <xsl:when test="string(ContentType)='LegalDocument'">
            <img align="absmiddle" src="_layouts/images/LegalDoc16.gif" border="0" alt="{imageurl/@imageurldescription}" />
        </xsl:when>
        <xsl:otherwise>
            <img align="absmiddle" src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />
        </xsl:otherwise>  
    </xsl:choose>   
  </div>

2条回答
霸刀☆藐视天下
2楼-- · 2019-05-31 13:51

I believe there is a bug that prevents the ContentType metadata property being used (see http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/cd059e1c-7af6-454c-8568-a22e7755ce8c)

You need to create a new managed metadata property and map it to the ows_ContentType crawled property (I called mine CType), after this do a full crawl (you may need to delete the index first) to have the property available in the search index.

Then edit the Search Core Results web part and add

 <Column Name="CType"/>

to Fetched Properties (under Display Properties) after <columns>

Then update your xml to the following

<xsl:choose>
    <xsl:when test="ctype = 'LegalDocument'">
        <img align="absmiddle" src="_layouts/images/LegalLinkedDocument.gif" border="0" alt="{imageurl/@imageurldescription}" />
    </xsl:when> 
    <xsl:otherwise>
        <img align="absmiddle" src="{imageurl}" border="0" alt="{imageurl/@imageurldescription}" />
    </xsl:otherwise>
</xsl:choose>

P.S. This question is possibly a duplicate of I think my xslt may not be formatted correctly

查看更多
等我变得足够好
3楼-- · 2019-05-31 13:53

Everthing was fine. All I had to do before running the powershell, go to the document library and add a file based on Linked to Document (and delete the test upload file). After that it worked.

查看更多
登录 后发表回答