Copied to clipboard

Flag this post as spam?

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


  • mark firth 32 posts 75 karma points
    May 02, 2012 @ 13:53
    mark firth
    0

    How ro check a node exists by URL

    Hi,

    Is there a way to check if a node exists by its url say like:

    getNodeByUrl(string URL) i ask as i have a site that will always have an English version of a document, but the user can select a region by a dropdown so when the links get written out via niceurl i want to know if another version exists so:

    /en/mypage/

    could be

    /fr/mypage/

            public static string NiceURLWithLocation(int nodeId)
            {

                string url = umbraco.library.NiceUrl(nodeId);

                if (HttpContext.Current.Session["LOCATION"] != null)
                {
                    if (url.IndexOf("/en/") != -1)
                    {

                        string tmp = url.Replace("/en/", "/" + HttpContext.Current.Session["LOCATION"].ToString() + "/");


    //this returns a page - not what i want - need to know if the node actually exists

                       System.Xml.XPath.XPathNodeIterator page = umbraco.library.GetXmlDocumentByUrl("http://"+HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + tmp);


                        if (page != null)
                        {
                            url = tmp;
                        }
                    }
                }
                return url;
            }

    Thanks in advance,

     

    Mark

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    May 02, 2012 @ 13:59
    Lee Kelleher
    1

    Hi Mark,

    In uComponents, we have an XSLT extension that can get you the ID of a node from it's URL

    var nodeId = uComponents.Core.XsltExtensions.Nodes.GetNodeIdByUrl("/path/to/content/page");

    Cheers, Lee.

  • mark firth 32 posts 75 karma points
    May 02, 2012 @ 14:12
    mark firth
    0

    Hi Lee,

     

    Thanks for the fast reply! Thats exactly what i was looking.

    Many thanks again,

    cheers,

    Mark

Please Sign in or register to post replies

Write your reply to:

Draft