Copied to clipboard

Flag this post as spam?

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


  • Bogdan 250 posts 427 karma points
    Oct 22, 2009 @ 16:08
    Bogdan
    0

    Read <items> from usercontrol

    Hi,

    how can I read the <items> from a .net usercontrol? myNode.GetProperty("myPropertyAlias").Value.ToString() returns null. Version or Alias work fine.

     

    Thank you!

  • Folkert 82 posts 212 karma points
    Oct 22, 2009 @ 17:12
    Folkert
    1

    You can acces the base properties of a node by using myNode.Name, or myNode.Id, or myNode.NodeTypeAlias. Custom added properties are accessed by using the GetProperty() method. myNode.GetProperty("customProperty").Value.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Oct 22, 2009 @ 17:16
    Jan Skovgaard
    0

    You can read a little more about the use of nodeFactory here http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-the-nodefactory

    /Jan

  • Bogdan 250 posts 427 karma points
    Oct 23, 2009 @ 09:27
    Bogdan
    0

    Like I said, I tried to read the <items> using myNode.GetProperty("myPropertyAlias").Value.ToString() but it returns null. All the other properties of the node, custom or not,  are ok.

  • Masood Afzal 176 posts 522 karma points
    Oct 26, 2009 @ 20:15
    Masood Afzal
    0

    bfi

    Please check the database if there is any value or alternatively you can use xslt to confirm if it works in xslt?

    As noted by Folkirt & Jan, myNode.GetProperty("customProperty").Value should work fine.

    thanks

     

     

     

  • Masood Afzal 176 posts 522 karma points
    Oct 26, 2009 @ 20:16
    Masood Afzal
    0

    xslt sample is available at http://umbraco.masoodafzal.com/

     

     

  • AbsCoder 5 posts 25 karma points
    Feb 08, 2010 @ 21:41
    AbsCoder
    0

    I've been having the same experience as the original poster. What I've discovered through trial and error is...

    The following works:

    var content = new umbraco.cms.businesslogic.Content(1234);
    var prop = content.getProperty("Repeatable");
    var val = prop.Value;

     

    However, using the node factory does not:

    var node = new Node(1234);
    var prop = n.GetProperty("Repeatable");
    var val = prop.Value;

    The value is null.

    This is my first day using Umbraco, so I'd appreciate any insight why the node factory wouldn't work, as others claimed it would . The factory does work for the other properties in the node, just not the Repeatable Custom Content.

    However, using the node factory does not:

    var node = new Node(1234);
    var prop = n.GetProperty("Repeatable");
    var val = prop.Value;

    The value is null.

    This is my first day using Umbraco, so I'd appreciate any insight why the node factory wouldn't work, as others claimed it would . The factory does work for the other properties in the node, just not the Repeatable Custom Content.

     

  • AbsCoder 5 posts 25 karma points
    Feb 08, 2010 @ 21:49
    AbsCoder
    0

    Sorry for the partial duplication in my above post; I hope you can tell where it should've ended. Are posts here not editable?

  • Masood Afzal 176 posts 522 karma points
    Feb 08, 2010 @ 22:10
    Masood Afzal
    0

    AbsCoder

    Can you please confirm if other properties on same node return correct value? Just to check if node is published?

    Masood

  • AbsCoder 5 posts 25 karma points
    Feb 08, 2010 @ 22:32
    AbsCoder
    0

    Hello, Masood. Yes, the other properties are correct. I'm fairly certain it's published -- if I use an XSLT macro, the Repeatable Custom Content values are populated with the expected content. I assume that means it's published.

    Thank you!

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 08, 2010 @ 23:29
    Thomas Höhler
    0

    First of all, you shouldn't use the umbraco.cms namespace for frontend retrieving of data (presentation). There you should use the NodeFactory mentioned by Jan before: http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-the-nodefactory

    Dirk had a good blogpost about the difference: http://www.netaddicts.be/articles/document-api-vs-nodefactory.aspx

    Second, if you are using the umbraco cms namespace you should use the umbraco.cms.businesslogic.web.Document...

    Take a look into the wiki describing the usage of this namespace: http://our.umbraco.org/wiki/reference/api-cheatsheet

    hth, Thomas

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 08, 2010 @ 23:31
    Thomas Höhler
    0

    To go in more detail: the content class is tha base class from the document class. The content class is also used by any other build in node in umbraco like the medias and the members (as I know).

  • AbsCoder 5 posts 25 karma points
    Feb 09, 2010 @ 02:15
    AbsCoder
    0

    @Thomas, thank you. I'm aware that I shouldn't use the cms name space, but rather the nodeFactory. In my post I stated the nodeFactory wasn't working for me, and I am trying to figure out why so that I may adhere to the best practices.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 09, 2010 @ 09:05
    Thomas Höhler
    0

    best practice is to use the nodefactory. So if you don't get the values it is another problem. Perhaps the xml isn't in sync. Try to recycle the app pool and republish the nodes. Also be sure that you have no typos for the properties, the aliases are case sensitive. So perhaps this is the problem. Hope you get it sorted :-)

  • AbsCoder 5 posts 25 karma points
    Feb 09, 2010 @ 20:11
    AbsCoder
    0

    Tried both recyling the app pool and republishing before I posted. No room for typos when doing something like this...

    Node myNode = new Node(1234);

    var lit = new Literal();
    lit.Text += "<b>PROPERTIES</b><br>";
    lit.Text += "Node Updated: " + myNode.UpdateDate + "<hr />";
    foreach (umbraco.presentation.nodeFactory.Property prop in myNode.Properties)
    {
        lit.Text += "Prop: " + prop.Alias + "<br />";
        lit.Text += "Version: " + prop.Version.ToString() + "<br />";

        if (prop.Value != null)
        {
            lit.Text += "&nbsp;&nbsp;Value: " + prop.Value + "<br />";
        }
        else
        {
            lit.Text += "&nbsp;&nbsp;Value: <b>IS NULL</b><br />";
        }
       
    }
    lit.Text += "<hr />";

    Values for the repeatable content(s) is still always null. All the other doc types show the current values and the date verified with the nodes updateDate property.

  • Nick 19 posts 39 karma points
    Apr 01, 2010 @ 01:20
    Nick
    0

    I have the same problem..has anyone found the solution yet?

  • Masood Afzal 176 posts 522 karma points
    Apr 02, 2010 @ 10:32
    Masood Afzal
    0

    Try something like:

     

    Document d = new Document(1234);

     

    string dataValue = d.getProperty("alias4RCC").Value.ToString();

  • Masood Afzal 176 posts 522 karma points
    Apr 02, 2010 @ 10:34
    Masood Afzal
    0

     

    private List<Hashtable> ToItemList(string propertyAlias)

    {

     

    List<Hashtable> list = new List<Hashtable>();

     

    Document d = new Document(Node.GetCurrent().Id);

    string dataValue = d.getProperty(propertyAlias).Value.ToString();

     

    if (string.IsNullOrEmpty(dataValue))

     

    return list;

     

     

     

    XmlDocument xmlDoc;

     

    try

    {

    xmlDoc =

    new XmlDocument();

    xmlDoc.LoadXml(dataValue);

    }

     

    catch

    {

     

    return list;

    }

     

    foreach (XmlNode itemNode in xmlDoc.DocumentElement.SelectNodes("/items/item"))

    {

    list.Add( ToItem(itemNode) );

    }

     

    return list;

    }

     

     

    private static Hashtable ToItem(XmlNode itemNode)

    {

     

    Hashtable item = new Hashtable();

     

    foreach (XmlNode node in itemNode.ChildNodes)

    {

    item.Add(node.Attributes[

    "alias"].Value.ToString(), node.InnerText);

    }

     

    return item;

    }

  • Paul Blair 466 posts 731 karma points
    Apr 22, 2010 @ 04:43
    Paul Blair
    2

    Hi,

    I can confirm having the same problem as AbsCoder i.e. the NodeFactory doesn't work dor this datatype.

    And to answer the original question, this is how I have bound the items to a repeater:

    XmlDocument xmlDoc = new XmlDocument();
    Document productDoc = new Document(productNode.Id);

    xmlDoc.LoadXml(productDoc.getProperty("productWeights").Value.ToString());
    ((Repeater) c).DataSource = xmlDoc.SelectNodes("/items/item");
    ((Repeater) c).DataBind();

    Cheers

    Paul

  • Paul Blair 466 posts 731 karma points
    Apr 22, 2010 @ 14:04
    Paul Blair
    2

    OK, I have tweaked my code from above to avoid using Document (and therefore use the XML cache instead and avoid a database hit). Here it is:

    xmlDoc.LoadXml(umbraco.library.GetXmlNodeById(productNode.Id.ToString()).Current.SelectSingleNode("data[@alias='productWeights']").InnerXml);
    ((Repeater)c).DataSource = xmlDoc.SelectNodes("/items/item");
    ((Repeater) c).DataBind();

    Seems to make a noticable difference performance wise even on localhost

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Jun 22, 2010 @ 12:28
    Stefan Kip
    0

    Thanks Paul

Please Sign in or register to post replies

Write your reply to:

Draft