Copied to clipboard

Flag this post as spam?

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


  • Nigel Wilson 945 posts 2077 karma points
    Nov 25, 2010 @ 17:52
    Nigel Wilson
    0

    Use xPATH on Media

    Hey

    I am building a photographic club website with online competitions.

    I have a media folder for each competition and all entries (images) stored within it.

    Within a members area I am developing a user control for members to maintain their competition entries (upload / delete).

    What I want to do is display current entries for the logged in member.

    My current code is below and works fine in terms of outputting the information. However I wonder if there is a better or quicker way to do this using xPATH that would avoid the looping part. Because I do not know how many images there will be I was wanting to ensure this is optimised.

    //Get Current Member
    Member currentMember = Member.GetCurrentMember();

    // Selected competition
    int compNodeID = Convert.ToInt32(ViewState["selectedCompetition"]);

    // Get competition media ID from document property
    Document compNode = new Document(compNodeID);
    int mediaCompNodeID = Convert.ToInt32(compNode.getProperty("mediaFolder").Value);

    //Get folder, loop through & identify those belonging to logged in member
    Media m = new Media(mediaCompNodeID);
    foreach (Media mChild in m.Children)
    {
      if (mChild.getProperty("memberID").Value.ToString() == currentMember.Id.ToString())
    {
        testOutput.Text += " - " + mChild.Id.ToString();
    }
    }

    Any suggestions ? Can you use XPATH in the same way you can within the Document XML ?

    Thanks

    Nigel

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Nov 25, 2010 @ 18:16
    Hendy Racher
    0

    Hi Nigel,

    You mentioned it didn't work for you in a previous post (not sure why), but this Helper Class also has a method called GetMediaFromXpath().

    (an alternative approach could be to use the Relations API to store the association between members and their photos)

    HTH,

    Hendy

  • Nigel Wilson 945 posts 2077 karma points
    Nov 26, 2010 @ 09:28
    Nigel Wilson
    0

    Hi Hendy

    As per the other forum post I have solved that issue and am rapt I figured out how to use the helper class.

    Now am attacking this issue with a bit more vigour however have not yet cracked it - so far I have:

    foreach (Media iMg in UmbracoHelper.GetMediaFromXpath("//Folder[@id='" + mediaCompNodeID + "']/competitionsImage"))

    The structure of my media is :

    Competitions (Folder media type)

        Competition 1 (Folder media type)

            Competition Image (competitionsImage media type)

    I have the Media folder ID which is in the "mediaCompNodeID" variable, hence trying to identify the correct folder by it's ID.

    Once I get this working I will then apply filtering on the Image - small steps I guess . . .

    Regards

    Nigel

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Nov 27, 2010 @ 18:25
    Hendy Racher
    1

    Hi Nigel,

    Glad you got GetNodesFromXPath() working on your other post (my mistake with the XPath typo ooops).

    I think you've highlighted a limitation with the GetMediaFromXPath() and GetMembersFromXPath() in that both of these methods build their source XML from the cmsContentXml table, generating a flat XML document, eg

    <Media>
      <Folder id=.. />
      <Image id=.. />
    </Media>

    So whilst the methods are useful to get Media and Members via their own attributes, it doens't support a hierarachy structure - I'll look into how this can updated.

    Have you considered using relation types to associate members with images ?

    Cheers,

    Hendy

  • Nigel Wilson 945 posts 2077 karma points
    Nov 28, 2010 @ 17:11
    Nigel Wilson
    0

    Hi Hendy

    Thanks for your response - helps remove the frustration I was feeling !

    No I haven't considered using relation types - I was not aware of such functionality.

    All images within the site are going to be uploaded via user controls so I definitely have the opportunity to create relationships between members and images.

    Will look into it further.

    Thanks for all your help - I appreciate it.

    Cheers

    Nigel

Please Sign in or register to post replies

Write your reply to:

Draft