Some little Umbraco snippets

 Cast/Parse Umbraco's DateTime Format

If you are in trouble formatting Umbraco's Datetime picker Date format in you server code.

here you have two ways to solve it. Imagine we have a porperty called endtime

DateTime _time= DateTime.ParseExact(Event.GetProperty("endTime").Value.ToString(), "yyyy-MM-ddTHH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);


DateTime _time = System.Xml.XmlConvert.ToDateTime(Event.GetProperty("endTime").Value.ToString());



How to get the base Url

In a Controller:

string hostHeader = Request.Headers["host"]; var host = new Uri(string.Format("{0}://{1}", Request.Url.Scheme, hostHeader));

If You need to access the request context in a Umbraco WebApiController, just use the Umbraco Helper

var requestContext = HttpContext.Current.Request.RequestContext;
var urlHelper = new System.Web.Mvc.UrlHelper(requestContext);

You could now get the current base Url like

var header = urlHelper.RequestContext.HttpContext.Request.Headers["host"];
var scheme = urlHelper.RequestContext.HttpContext.Request.Url.Scheme;
var host = new Uri(string.Format("{0}://{1}", scheme, header));


Caglar Tasci

Beauty is more important in computing than anywhere else in technology because software is so complicated. Beauty is the ultimate defence against complexity. — David Gelernter

comments powered by Disqus