Umbraco Helper Class
Umbraco Helper Class
It may be an UmbracoHelper.cs class, but it’s essentially groups of useful static methods. The first two tables refer to getting Nodes, Media Items and their Properties, whilst the third table refers to an enum and attributes for use with Umbraco ObjectTypes.
| umbraco.presentation.nodeFactory.Node | ||
|---|---|---|
| Retuns | Method | Parameters |
| Node | GetRootNode | () |
| Node | GetNode | (string nodeID) |
| Node | GetChildNodeByName | (string nodeName) |
| (string nodeName, Node parentNode) | ||
| List<Node>[1] | GetNodesByName | (string nodeName) |
| List<Node>[1] | GetNodesFromCsv | (string csv) |
| List<Node>[1] | GetNodesFromXpath | (string xPath) |
| List<Node>[1] | GetNodesFromIterator | (XPathNodeIterator iterator) |
| List<Node>[1] | PickRandomNodes | (List<Node>[1] nodes, int count, int sampleSize) |
| string | GetNodeProperty | (string propertyName) |
| (int nodeID, string propertyName) | ||
| (Node node, string propertyName) | ||
| umbraco.cms.businesslogic.media.Media | ||
|---|---|---|
| Retuns | Method | Parameters |
| Media | GetMediaItem | (string mediaID) |
| List<Media> | GetMediaFromCsv | (string csv) |
| string | GetMediaProperty | (int mediaID, string propertyName) |
| (Media media, string propertyName | ||
The Get…FromCsv methods are useful with the built-in UltimatePicker and other pickers that have adopted storing comma seperated Ids. For example the Sidebar Widgets post would benefit by removing the GetSidebarWidgets() method, and populating the repeater with :
[1] A generic List collection of Nodes was chosen in preference to the umbraco.presentation.nodeFactory.Nodes object so as to be able to apply sorts easily, and to remain consistant with how Media collections are returned.
The following table refers to methods that use an Enum called UmbracoObjectType, which is used to associate the collection of the Umbraco Guids with thier friendly names. These methods were useful for the Relation Types package where DropDownLists for each of the Umbraco ObjectTypes were needed.
| UmbracoObjectType | ||
|---|---|---|
| Retuns | Method | Parameters |
| Guid | GetGuid | (UmbracoObjectType umbracoObjectType) |
| string | GetName | (UmbracoObjectType umbracoObjectType) |
| string | GetFriendlyName | (UmbracoObjectType umbracoObjectType |
| UmbracoObjectType | GetUmbracoObjectType | (string name) |
| (Guid guid) | ||
From: http://blog.hendyracher.co.uk

