Copied to clipboard

Flag this post as spam?

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


  • Jeff Chapin 18 posts 39 karma points
    Jun 22, 2011 @ 20:50
    Jeff Chapin
    0

    How to get ID from URL

    Does anyone know an easy way to get the ID of a file given the URL?

    If it helps to know why I want the Id...  I'm trying to do deep linking into the Umbraco editor.  For example a typical deep link looks like this.
    http://www.mySite.com/umbraco/umbraco.aspx?app=content&rightAction=editContent&id=1549#content

    If I want to edit 'about-Us.aspx' for example I need to convert 'about-Us.aspx' to '1549' to open the editor on that page.

    I tried using GetXmlDocumentByUrl but I have no idea.
    string
    GetNodeID_ByUrl(string nodeURL)
    {
    try
    {
     
    return umbraco.library.GetXmlDocumentByUrl(nodeURL).Current.GetAttribute("Id", "");
    }
    catch
    {
     
    return "not"
    }
    }

    Thanks!

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 22, 2011 @ 21:05
    Tom Fulton
    0

    Hi,

    I don't quite understand why you need to do this - where are you getting the URL from, you should be able to get the ID from the same place, no?

    If not, you could try a helper method in uQuery from uComponents - GetNodeByUrl(string url), and do something like:

    Node n = uComponents.Core.uQuery.GetNodeByUrl("about-us.aspx");
    if (n != null)
    int nodeid = n.Id;

    Not quite sure on the format the URL needs to be in, perhaps "/about-us.aspx"

    -Tom

  • Jeff Chapin 18 posts 39 karma points
    Jun 22, 2011 @ 21:21
    Jeff Chapin
    0

    The URL is comming from a client side javascript.  I'm developing a browser based way of navigating through the Umbraco editor.

    What references to I need to add to my project for uComponents to work?

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 22, 2011 @ 21:23
    Tom Fulton
    0

    Just add a reference to uComponents.Core.dll which you can get from the package or build from the source.

    -Tom

  • 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