Copied to clipboard

Flag this post as spam?

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


  • Sean 141 posts 179 karma points
    Apr 16, 2011 @ 04:00
    Sean
    0

    Accessing current node properties causes object exception

    Hi There,

    I'm using the function below to generate a list of nodes from my site. I'm wanting to access the properties of the of the document type in order to use more conditional logic but I'm getting the "Object reference not set to an instance of an object." . I have suspect bit of code marked in bold. Can someone help me fix this code please?

    Thanks in advance.

    Sean

     

       public void iterateNodes(umbraco.presentation.nodeFactory.Node node)
            {
                if (node.Children.Count > 0)
                {
                    var childNodes = node.Children;
                    foreach (umbraco.presentation.nodeFactory.Node childNode in childNodes)
                    {
                        string strURL = umbraco.library.NiceUrl(childNode.Id);


                        Response.Write(childNode.GetProperty("umbracoNaviHide").Value.ToString());

                        if (childNode.NodeTypeAlias == "HomepageType")
                        {
                            strb.AppendFormat("<li><a href=\"/\">Home</a></li>");
                        }
                        if (childNode.Children.Count > 0 && childNode.NodeTypeAlias != "HomepageType" && childNode.NodeTypeAlias == "SubPageType")
                        {
                                strb.AppendFormat("<li>");
                                strb.AppendFormat("<a href=\"{0}\">{1}</a>", strURL.ToString(), childNode.Name);
                                strb.AppendFormat("<ul>");
                             
                                    foreach (umbraco.presentation.nodeFactory.Node j in childNode.Children)
                                    {
                                        strb.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", strURL.ToString(), j.Name);
                                    }
                             
                                strb.AppendFormat("</ul>");
                                strb.AppendFormat("</li>");
                          
                        }
                        iterateNodes(childNode);
                    }


                    Literal1.Text = strb.ToString();
                }
            }

  • Richard Soeteman 4047 posts 12900 karma points MVP 2x
    Apr 16, 2011 @ 07:23
    Richard Soeteman
    1

    Hi Sean,

    You propably get the error because the umbracoNaviHide property doesn't exist on your child nodes. So before getting the value check that GetProperty doesn't return null

    If(childNode.GetProperty("umbracoNaviHide") != null){..........

    Hope this helps you. Cheers,

    Richard

  • Sean 141 posts 179 karma points
    Apr 16, 2011 @ 08:21
    Sean
    0

    Oh man. I can't believe I missed that. Thanks a bunch for the help.

Please Sign in or register to post replies

Write your reply to:

Draft