Created
May 6, 2011 17:07
-
-
Save mattbrailsford/959339 to your computer and use it in GitHub Desktop.
Umbraco Media Icons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using umbraco.BusinessLogic; | |
using umbraco.cms.businesslogic.media; | |
using umbraco.cms.presentation.Trees; | |
using umbraco.IO; | |
namespace TheOutfield.UmbExt.MediaIcons.Logic | |
{ | |
public class AppBase : ApplicationBase | |
{ | |
public AppBase() | |
{ | |
BaseTree.BeforeNodeRender += BaseTree_BeforeNodeRender; | |
} | |
protected void BaseTree_BeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e) | |
{ | |
if (node.NodeType != "media") return; | |
var ext = ""; | |
var mediaItem = new Media(Convert.ToInt32(node.NodeID)); | |
if (mediaItem.ContentType.Alias != "Folder") | |
{ | |
var mediaFileProp = mediaItem.getProperty("umbracoFile"); | |
if (mediaFileProp != null) | |
{ | |
var mediaFile = mediaFileProp.Value.ToString(); | |
if (!string.IsNullOrEmpty(mediaFile) && mediaFile.LastIndexOf(".") < mediaFile.Length) | |
{ | |
ext = mediaFile.Substring(mediaFile.ToLower().LastIndexOf(".") + 1); | |
} | |
} | |
} | |
if (!string.IsNullOrEmpty(ext)) | |
{ | |
var iconUrl = string.Format("/umbraco/images/umbraco/{0}.gif", ext); | |
if (File.Exists(IOHelper.MapPath(iconUrl))) | |
{ | |
node.Icon = ext + ".gif"; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment