Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Media fallback
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
You can’t perform that action at this time.