Umbraco 4.0.3 Coming Soon

Monday, September 28, 2009 by Chris Larson

Umbraco 4.0.3 will be released in the next few days providing some important bug fixes to the way the environment works. Companies currently hosting with us will be upgraded automatically within a week of the upgrade release after we have tested the upgrade process and ensure that your sites continue to work.

Looking for worry-free Umbraco hosting with knowledgeable and response staff and support? We can provide it! From simple, shared hosting plans to dedicated virtual servers and complete dedicated environments, contact us today to arrange hosting with us. We can help migrate your existing Umbraco site or get you up and running on the premier .NET content management platform.

Google Maps w/ Real Time Actions (repost)

Friday, July 03, 2009 by Chris Larson

The Google API behind this is rather easy actually. You would start by registering an API Key for Google here: http://code.google.com/apis/maps/

Next, you will want to read a little about the API and browse through some of the samples to get some familiarity. The basic code for rendering an object on the map looks like this:

<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=[yourgooglemapsAPIkey]"></script>
��� <script type="text/javascript">

��� var map = null;
��� var geocoder = null;
���
��� function initialize() {
����� if (GBrowserIsCompatible()) {
������� map = new GMap2(document.getElementById("map_canvas"));
������� map.setCenter(new GLatLng(37.4419, -112.1419), 13);
������� geocoder = new GClientGeocoder();
����� }
��� }
���
��� function showAddress(address, caption) {
����� if (geocoder) {
������� geocoder.getLatLng(
��������� address,
��������� function(point) {
����������� if (!point) {
������������� alert(address + " not found");
����������� } else {
������������� map.setCenter(point, 13);
������������� var marker = new GMarker(point);
������������� map.addOverlay(marker);
������������� marker.openInfoWindowHtml(caption);
����������� }
��������� }
������� );
����� }
��� }
��� </script>
��� <script type="text/javascript" language="javascript">
�initialize();
��� </script>

We also need to add a DIV element to the control to render the map and a literal control to call the javascript.


<div id="map_canvas" style="width: 500px; height: 480px; float:left; border: 1px solid black;"></div>
<asp:literal id="scriptrunner" runat="server" />

In the "ShowAddress" function, you will want Umbraco to get the latest result, event, etc... to display. This example will demonstrate how to do that with the API.


Start with the Node ID that contains all the child objects (Example: A Node:Events may contain many children events underneath it like so)


+ Root
�� + Events
������ + Event #1 (Date 7/3/2009)
������ + Event #2 (Date 8/15/2009)
������ + Event #3 (Date 7/21/2009)

In your .NET Control, we first need to perform some setup. We have one public property for the "root node" that can be defined at the macro level as a contentPicker to make this easily customizable for the end user. This does not have to be public or set up on the macro, but I'm a fan of reusable code.


Imports umbraco.presentation.nodeFactory
Imports umbraco.library

Public Class GoogleMapHandler
Private NodeID As Integer
Private CalendarNodeID As Integer

Public WriteOnly Property intNodeID() As Integer
��� Set(ByVal value As Integer)
������� NodeID = value
��� End Set
End Property

Next we set up the Page_Load event in the code behind for the user control. In here, we are going to loop through the children of the selected root node and add them to a datatable. This will allow us to sort the resulting output by creating a data view around the table. Also, we are going to make sure that we only add records to the dataview that are less than one day old. This will help to limit the result set and reduce the memory load on the web server and increase the rendering speed when there are very large structures.


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
������� Dim n As Node = New Node(NodeID)

' Set up the datatable to contain all the elements we need for the map
������� Dim oTable As New Data.DataTable
������� oTable.Columns.Add(New Data.DataColumn("nodeid"))
������� oTable.Columns.Add(New Data.DataColumn("createdate", GetType(DateTime)))
������� oTable.Columns.Add(New Data.DataColumn("address"))
oTable.Columns.Add(New Data.DataColumn("caption"))

�<span style="white-space:pre"> </span>' Loop through the children of the selected root node and add each one to the hashtable as a GoogleMapData object
������� For Each child As Node In n.Children
����������� If child.CreateDate >= DateAdd(DateInterval.Day, Now(), -1)
����������� ' add an item to the data view
�� Dim oMapData As DataRow = oTable.NewRow()
���������������� oMapData.NodeID = child.Id
���������������� oMapData.CreateDate = child.CreateDate
���������������� oMapData.Address = child.GetProperty("address").Value
���������������� oMapData.Caption = child.GetProperty("caption").Value
���������������� oTable.Rows.Add(oDataRow)
��� End If<br />������� Next����

' Once we have the data in a table, we are going to create a new Data View that we can use to sort the information <span style="white-space:pre">������� </span>' quickly

Dim oDataView As DataView = New DataView(oTable)

' Now sort the view in descending order to make sure the most recent event is first
oDataView.Sort = "CreateDate DESC"

' Finally, get the data from the row and cram it in to our JavaScript for the Map
scriptrunner.Text = "<script language=""javascript"" type=""text/javascript"">" & _
�"showAddress('" & oDataView(0)("address") & "','" & oDataView(0)("caption") & "');" & _
�"</script>"

End Sub�������

I haven't tested this code example, but there is a similar version of this code working in a beta mode at http://www.wicatech.net/calendar-events/event-1.aspx.

Happy coding!

Creating Member Types through Code

Friday, May 29, 2009 by Chris Larson

This entry focuses on how to create a member type and add extended properties to the member type after creation. As membership controls for Umbraco 4.01 are not part of the default installation, this is one part of creating a membership module for Umbraco.

To start, we have to add a new member type to the system. This is done by instantiating a new MemberType object and assigning basic properties to the new member type.

VB Code:

Imports umbraco.cms.businesslogic.member

Dim oMemberType As MemberType = MemberType.MakeNew(New umbraco.BusinessLogic.User(0), "[WICATech]MailListUser")

oMemberType.Alias = "[WICATech]MailListUser"
oMemberType.Description = "Default Mailing List Group for WICA Extensions"
oMemberType.Thumbnail = "membergroup.png"
oMemberType.Save()

[End Code]

When we call the .Save() method of MemberType, the MemberType will carry a new ID which can then be used to add a new custom property to the member.

[VB Code]

Dim oPropertyType As umbraco.cms.businesslogic.propertytype.PropertyType = _
umbraco.cms.businesslogic.propertytype.PropertyType.MakeNew( _
New umbraco.cms.businesslogic.datatype.DataTypeDefinition(-49), _
New umbraco.cms.businesslogic.ContentType(oMemberType.Id), "Opt In", "bOptIn")

Note that we use MemberType.ID for the content type. This is because MemberTypes are considered a Content Type item in Umbraco. Also note that the DataTypeDefinition is set as "-49". That value represents a True/False data type. A complete list of data types can be found below, or you can use the following T-SQL statement to build a list yourself:

select id, text from umbracoNode where id < -1

LIST

id text

----------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-92 Label

-90 Upload

-89 Textbox multiple

-88 Textstring

-87 Richtext editor

-51 Numeric

-49 True/false

-43 Checkbox list

-42 Dropdown

-41 Date Picker

-40 Radiobox

-39 Dropdown multiple

-38 Folder Browser

-37 Approved Color

-36 Date Picker with time

-20 Recycle Bin

Iterating Properties of a Node in .NET

Tuesday, May 26, 2009 by Chris Larson

After numerous failed attempts at figuring out how to get the properties of a document and searching through the Umbraco forums, I finally figured out how to iterate through the properties of a node to get what I was looking for.

[VB.NET]

imports umbraco.presentation.nodeFactory

Partial Public Class IterateSample
Inherits System.Web.UI.UserControl

Private intPageID as Integer = 0

Public WriteOnly Property PageID() As Integer
�� Set(ByVal value As Integer)
������ intPageID = value
�� End Set
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

' using the page id to get the current document, loop through the node properties and render to the screen

Dim n As Node = New Node(intPageID)
For i As Integer = 0 To n.Properties.Count - 1
��� ltTags.Text &= n.Properties(i).Alias.ToString & " | " & n.Properties(i).Value.ToString & "<br/>"
Next

End Sub

End Class