Copied to clipboard

Flag this post as spam?

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


  • greengiant83 88 posts 109 karma points
    Mar 16, 2011 @ 17:05
    greengiant83
    0

    Accessed saved property from custom data type

    I have a user control setup as a custom data type using the IUsercontrolDataEditor.  It needs know one of the other property values of the document. I was doing this the NodeFactory.GetCurrent().GetProperty("...") but this wont get me the lasted value if the document is only saved and not published.

    How can I get the most up to date value?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 16, 2011 @ 17:27
    Tom Fulton
    1

    Hi,

    NodeFactory only accesses published data.  To access "saved" data you'll want to use the Document API.  Typically when you are working on the backend you'll always want to use the Document API for this reason.

    The usage is pretty similar:

    using umbraco.cms.businesslogic.web;


    Document d = new Document(1234);
    string x = d.getProperty("...").Value;

    Note there is no equivalent of .GetCurrent() to get the current document, but if in the backend you can grab it from the 'id' querystring, something like:

    Document d = new Document(Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]));

    Hope this helps,
    Tom

     

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 16, 2011 @ 17:32
    Hendy Racher
    0

    Hi,

    You can use the Document API as this will work with the values from the database, (the NodeFactory works with the values from the published XML).

    using umbraco.cms.businesslogic.web; // Document
    using umbraco.presentation.nodeFactory; // Node

    Document document = new Document(Node.GetCurrent().Id);
    object propertyValue = document.getProperty("...").Value;

    HTH,

    Hendy

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 16, 2011 @ 17:38
    Hendy Racher
    0

    oops, I was too slow to answer :) and as Tom correctly points out to get the current node from a custom datatype you'll need to query the QueryString (or use the uComponents uQuery.GetCurrentNode() which will first attempt to use the node factory and if it's not available then will try to take it from the QueryString)

Please Sign in or register to post replies

Write your reply to:

Draft