Created
May 21, 2014 10:46
-
-
Save mortenbock/e21f4a00e068c02f0ab1 to your computer and use it in GitHub Desktop.
Media fallback
This file contains 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
public static string GetOptionalMediaUrl(this INode node, string propertyAlias) | |
{ | |
int? mediaId = node.GetOptionalNullableValue<int>(propertyAlias); | |
if (mediaId.HasValue) | |
{ | |
XPathNodeIterator media = library.GetMedia(mediaId.Value, false); | |
//we look at both //Image and //node, because some media items may not have been saved since the schema changed. | |
var file = media.Current.SelectSingleNode("//Image/umbracoFile | //node/data[@alias='umbracoFile']"); | |
if (file != null) | |
return file.InnerXml; | |
} | |
return string.Empty; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment