Copied to clipboard

Flag this post as spam?

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


  • Vincent Ashby-Smith 67 posts 196 karma points
    Mar 26, 2010 @ 13:20
    Vincent Ashby-Smith
    0

    PageName in c# code behind?

    Hi all i was wondering if its possible to get the page name in c#? I need it to build a string with the page name in it, which i'm doing all in a template using c# code behind!

  • Petr Snobelt 923 posts 1535 karma points
    Mar 26, 2010 @ 14:12
    Petr Snobelt
    0

    Look at properties of Node and use umbraco.presentation.nodeFactory.Node.GetCurrent() to get current node

    http://en.wikibooks.org/wiki/Umbraco/Samples_and_Articles/Dot_Net_Controls/Access_Umbraco_Data_With_Dot_NET_Controls

    P.

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Mar 26, 2010 @ 14:15
    Lee Kelleher
    0

    Hi Vincent,

    Have a read over the wiki articles for the API, specifically the nodeFactory and Document classes/objects:

    http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-the-nodefactory

    http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-a-node-and-a-document

    Quick example:

    Document doc = new Document(id);
    String pageName = doc.Text;

     

    Cheers, Lee.

  • Frederik Vig 29 posts 61 karma points
    Mar 26, 2010 @ 14:31
    Frederik Vig
    2

    Use the umbraco.presentation.nodeFactory.Node.GetCurrent() method like Petr describes, and the Name property.

    Node node = umbraco.presentation.nodeFactory.Node.GetCurrent();
    string name = node.Name;

    The reason for this is that Node uses the data that is cached, while Document actually makes an SQL call to the database, so only use it when you need to change the data in some way.

    Hope this helps.

    Frederik

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Mar 26, 2010 @ 15:29
    Lee Kelleher
    0

    ... or if you need to access unpublished content.

  • 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