Friday, June 3, 2011

Create a favorites icon (favicon) for your SharePoint 2010 site

With SharePoint 2010, Microsoft has provided a new control called SPShortcutIcon. Sadly, if you are trying to use this within a feature deployment and would like to use relative paths using $SPUrl variables, you will run into some issues. This is because the SPShortcut.IconUrl is of type URI and the $SPUrl variable cannot be cast properly. Fortunately, there is a work around. It’s a bit ugly, but instead of using the control, you can use Literal controls to render the proper html link control.
SPShortcut usage– This is hardcoded, so won’t work with feature deployments.
<SharePoint:SPShortcutIcon runat="server" IconUrl="/Style Library/Waffles/favicon.ico"/>
SPShortcut usage with $SPUrl – This will result in the following error: Unable to cast object of type 'System.String' to type 'System.Uri'.
<
SharePoint:SPShortcutIcon runat="server" IconUrl="<% $SPUrl:~sitecollection/Style Library/Acme/favicon.ico %>" />
Solution


<
asp:Literal runat="server" Text="&lt;link rel='shortcut icon' href='" /><asp:Literal runat="server" Text="<% $SPUrl:~sitecollection/Style Library/Acme/favicon.ico %>" /><asp:Literal runat="server" Text="' type='image/vnd.microsoft.icon' /&gt;" />
Google.com’s favorite icon

image
SharePoint 2010, Favorites Icons (FavIcons) and SPUrl (SPUrlExpressionBuilder)Credit goes to Joel for this tip. Unfortunately, I could only get to his post via Google cache.http://joelblogs.co.uk/2010/11/09/sharepoint-2010-favorites-icons-favicons-and-spurl-spurlexpressionbuilder/

4 comments:

  1. Great blog very nice information i really like your post. Your article its so amazing. After reading your blog i am very helpful & i really thanks full your. Keep blogging.

    ReplyDelete
  2. So why not point the IconUrl to the something like "/_layouts/1033/styles/favicon.ico"?

    ReplyDelete
  3. This was helpful. Thank you

    ReplyDelete
  4. Do you know how to make this string (<% $SPUrl:~sitecollection/Style Library/Acme/favicon.ico %>) work in SP2016 html master page?

    ReplyDelete