Copied to clipboard

Flag this post as spam?

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


  • Dominic Dore 18 posts 38 karma points
    Jul 12, 2011 @ 20:23
    Dominic Dore
    0

    Listing Media from a folder through .net usercontrols

    Hello all!

    I am currently trying to list media files inside a media folder from the media tab in Umbraco, and I am having a little bit of an issue. What I am currently doing is creating the current page into a Node by doing Node.GetCurrent(); I am then creating a Node out of the media folder (alias = "mediaFolder") by using the Node ID of that property on the page (new Node(Int32.Parse(currentPage.GetProperty("mediaFolder").Value)); For some reason when I create this new Node, it has no children, but when i create an XPathNodeIterator by calling GetMedia on the mediaFolder's Node ID, the XPathNodeIterator's hasChildren attribute is true. Can anyone tell me why the Node has no children when I'm trying to recreate it??? I would appreciate the help a TON! Thanks a lot in advance.

    Cheers!

    - Dom

  • Dominic Dore 18 posts 38 karma points
    Jul 12, 2011 @ 22:03
    Dominic Dore
    0

    Update: The new Node is not recreating the original Node... it is just making a blank Node with no Id or anything... everything is blank. Any clues as to why it would do this?

    - Dom

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jul 13, 2011 @ 12:06
    Bo Damgaard Mortensen
    0

    Hi Dominic,

    Just to get a better understanding of your problem: the mediaFolder property on your document holds the id of the media folder (i.e. a mediapicker), or am I wrong here? :-)

  • Dominic Dore 18 posts 38 karma points
    Jul 13, 2011 @ 15:17
    Dominic Dore
    0

    Hello Bo,

    Yes. The mediaFolder property is a mediapicker which i chose to be a folder in the media tab containing multiple media items, such as images and/or pdf files.

  • Dominic Dore 18 posts 38 karma points
    Jul 13, 2011 @ 20:30
    Dominic Dore
    0

    Update: I was able to solve the problem, however I took a different approach and I have a new problem.

    During my last approach, I was trying to access the folder by creating a node that was basically a clone of it (using it's node ID to create a new node). When I did this everything in the newly created node was null, including the Id attribute, so I decided to do it differently.

    In my new approach, I created an XPathNodeIterator (we'll call it nodeIt) from umbraco.library.GetMedia(nodeID, true). When you use true as the second parameter it allows you to access the parent node's child nodes. I then used nodeIt.Current.SelectSingleNode("//umbracoFile").Value to set the link's url to the first child's path. My new problem is that this only accesses the first child Node and it doesn't recognize any other child items. Any thoughts?

  • Dominic Dore 18 posts 38 karma points
    Aug 09, 2011 @ 21:10
    Dominic Dore
    0

    For those who may be reading this post in the future, I have recently found out that Documents are much more accessible than Nodes in the backend. To retrieve an item through the backend, I recommend Document doc = new Document(ID), rather than Node node = new Node(ID); See this post, it helped me understand why Documents are a better choice: http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-a-node-and-a-document . Thanks!

    -Dom

Please Sign in or register to post replies

Write your reply to:

Draft