Skip to content

Instantly share code, notes, and snippets.

Morten Bock mortenbock

Block or report user

Report or block mortenbock

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:e21f4a00e068c02f0ab1
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;
View DittoTemplatePage.cs
using System.Web.Mvc;
using Our.Umbraco.Ditto;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
namespace MappingDemo.Custom.Mvc
public abstract class DittoTemplatePage<T> : UmbracoTemplatePage where T : class
View ConfigFactory.cs
using Our.Umbraco.Ditto;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
namespace MappingDemo.Custom.Mvc
public class ConfigFactory : ApplicationEventHandler
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
mortenbock / UmbImage.cs
Created Sep 28, 2012
Simple helper renderer
View UmbImage.cs
using umbraco.NodeFactory;
namespace Sample.Web.UI
public class UmbImage : System.Web.UI.HtmlControls.HtmlImage
public string Field
mortenbock /
Created Sep 28, 2012
Ideas for usage of umbraco:image

Suggested sample usage of umbraco:Image

All attributes from the normal <img /> can be used. The idea then is to let different providers help generate the correct src attribute, based on the parameters given by the user. The reason for using an options attribute for input to the provider, is that you might want the server to render the image at a certain size, but not actually have the width attribute on the rendered image.

I have restricted it to images for now. It might be possible to create an umbraco:Media that would handle videos or sound as well, but I think images are the most valuable thing to operate with.

I have created some samples of how I think it could be used.

Regular image

mortenbock / ImageUrlProvider.cs
Created Oct 4, 2012
ImageGen sample implementation
View ImageUrlProvider.cs
namespace UmbImageDemo
public class ImageUrlProvider : IImageUrlProvider
public string Name
get { return "imageGen"; }
public string GetImageUrlFromMedia(int mediaId, IDictionary<string, string> parameters)
View gist:4017307
.Select(i=> new Foo(i))
//Mark these two lines
.Select(i=> new Foo(i))
View gist:6086963
<!-- Ensure Compatability for old log4net version, that has different public key.-->
<assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
<codeBase version="" href="bin\log4netv1.2.10.0\log4net.dll" />
mortenbock / MyModel.cs
Created Aug 1, 2013
Custom viewmodel in Umbraco
View MyModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace UmbSample.Models
public class MyModel
public string Title { get; set; }
mortenbock / Constrain.cs
Created Oct 10, 2013
Constraining images with imageprocessor
View Constrain.cs
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using ImageProcessor;
using ImageProcessor.Helpers.Extensions;
using ImageProcessor.Processors;
using ImageProcessor.Web.Config;
namespace Demo.ImageProcessors
You can’t perform that action at this time.