Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rob Watkins 370 posts 703 karma points
    Nov 22, 2010 @ 16:28
    Rob Watkins
    0

    Loading from XML properties (e.g. PDCalendar)

    I don't know where else to put this I'm afraid; I made a modification to your code to allow it to read dates from XML properties as used in PDCalendar; it is a simple change that adds the ability to read an XPath from the config, e.g.

    <add key="itemDateProperty" value="testDate/pdcalendarevent/pdcstart"/>

    The XPath is a bit of a cheat; the first element is the property alias, then the rest is the XPath for the XML contained in that property.

            public static string GetPropertyValueAsString(this UmbracoDocument document, string propertyAlias)
            {
                String res = String.Empty;
    
                // Get alias type = name or name / path
                String path = null;
                Match m = Regex.Match(propertyAlias, @"^([\w\d_]+?)(/.+)$");
                if (m.Success)
                {
                    propertyAlias = m.Groups[1].Value;
                    path = m.Groups[2].Value;
                }
                //
    
                umbraco.cms.businesslogic.property.Property prop = document.getProperty(propertyAlias);
                if (prop != null)
                {
                    if (path != null)
                    {
                        XmlDocument doc = new XmlDocument();
                        XmlNode np = prop.ToXml(doc);
    
                        if (np != null)
                        {
                            XmlNode nv = np.SelectSingleNode(path);
    
                            if(nv != null)
                                res = (nv is XmlElement ? nv.InnerText : nv.Value);
                        }
                    }
                    else if(prop.Value != null)
                        res = prop.Value.ToString();
    
                }
    
                return res;
            }
    
    I'm new to Umbraco development, so this may not be the best way to do things, but it does work.
    Also, please delete and ask me to repost in a more appropriate place if there is one!
  • Stefan Kip 1614 posts 4131 karma points c-trib
    Nov 22, 2010 @ 17:11
    Stefan Kip
    0

    I guess this is the correct spot to post this. The only fault you've made is posting it twice :P

  • Rob Watkins 370 posts 703 karma points
    Nov 22, 2010 @ 18:43
    Rob Watkins
    0

    Yes, I don't know what happened there! I tried to delete it twice! I'll give it another go now :o)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies