November Happy Hour will be moved to Thursday December 5th.

ProjectImageUriFrom

Vote:
 

In my Global.asax.cs file I have the following code:

            SearchClient.Instance.Conventions.UnifiedSearchRegistry
                .ForInstanceOf()
                .CustomizeProjection(
                    x => x.ProjectImageUriFrom(
                        page => GetPageImage(page)));

where

        private static Uri GetPageImage(SitePageData page)
        {
            try
            {
                var baseArticlePage = page as BaseArticle;
                if (baseArticlePage != null && baseArticlePage.ArticleImage != null)
                {
                    var url = baseArticlePage.ArticleImage.OriginalString;
                    if (!string.IsNullOrWhiteSpace(url))
                        return new Uri(url, UriKind.Relative);
                }

                if (page is ArticlePage)
                    return new Uri("/static/gfx/pages/article-page.png", UriKind.Relative);
                if (page is CalendarPage)
                    return new Uri("/static/gfx/pages/calendar-page.png", UriKind.Relative);
                if (page is EmployeePage)
                    return new Uri("/static/gfx/pages/employee-page.png", UriKind.Relative);
            }
            catch (Exception)
            {
                return new Uri("/static/gfx/pages/article-page.png", UriKind.Relative);
            }

            return new Uri("/static/gfx/pages/article-page.png", UriKind.Relative);
        }

and when I dispay my search results I use 

but I don't get any image at all for pages...

But when I display file icons then everything works fine when I use

            SearchClient.Instance.Conventions.UnifiedSearchRegistry
                .ForInstanceOf()
                .CustomizeProjection(
                    x => x.ProjectImageUriFrom(
                        file => GetFileImage(file.Extension)));

where

        private static Uri GetFileImage(string extension)
        {
            if (extension == ".doc")
                return new Uri("/static/gfx/extensions/file_doc.png", UriKind.Relative);
            if (extension == ".docx")
                return new Uri("/static/gfx/extensions/file_docx.png", UriKind.Relative);
            if (extension == ".pdf")
                return new Uri("/static/gfx/extensions/file_pdf.png", UriKind.Relative);
            if (extension == ".txt")
                return new Uri("/static/gfx/extensions/file_txt.png", UriKind.Relative);
            if (extension == ".xls")
                return new Uri("/static/gfx/extensions/file_xls.png", UriKind.Relative);
            if (extension == ".xlsx")
                return new Uri("/static/gfx/extensions/file_xlsx.png", UriKind.Relative);

            return new Uri("/static/gfx/extensions/file_default.png", UriKind.Relative);
        }

Am I missing something?

#113770
Nov 27, 2014 14:37
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.