Copied to clipboard

Flag this post as spam?

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


  • Toni Becker 146 posts 425 karma points
    Aug 05, 2011 @ 21:26
    Toni Becker
    0

    Help needed - Tricky Data and get them - different methods failed -

    Okay here's my Problem. I have 2 Documenttypes Portfolio and Portfolioitem.

    in Portfolioitem i have DAMP with multiple stored Images. The Property is portfolioImages.

    Okay i've started out with the following:

    @{
    var start = Model.AncestorOrSelf(1).Descendants("PortfolioItem");
    }
    @foreach(dynamic item in start)
    {
    foreach(var c in item.portfolioImages)
    {
    <li>
    <img src="@c.Image.umbracoFile" />
    </li>
    }
    }

    Everything works fine, but i have the problem that i can't use the .Take(10) or something else.

    Somebody have an idea how to do the trick better than that.

    Thanks for every usefull tip.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 05, 2011 @ 22:37
    Jeroen Breuer
    0

    You can't use .Take or .Skip on DynamicXml. You could use LinqToXml instead to do this.

    Jeroen

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Aug 08, 2011 @ 02:01
    Anthony Dang
    0

    There is a problem with extension methods on dynamic objects.

    If you instantiate a DynamicNode, then call those methods on it, you will have access to Take()

    eg.  

    @{
    var start = new DynamicNode(Model.Id).AncestorOrSelf(1).Descendants("PortfolioItem");
    }
  • Toni Becker 146 posts 425 karma points
    Aug 08, 2011 @ 12:47
    Toni Becker
    0

    This is my XML and now i will do the following:

    go to the root and check all nodes with Alias PortfolioItem i have multiple of these.

    Next step-> Loop over the property portfolioImages (DAMP) and get all the mediaItems from those

    Next step->my logic is to put all the mediaItem nodes in a DynamicNodeList and use the .Take(10).OrderBy("someDate desc") for a slideshow on a homepage with recent artworks.

    I hope somebody has a solution or first steps to go on with the problem.

    Thanks to all hints. Greetings Toni

    <PortfolioItem id="1171" parentID="1072" level="3" writerID="0" creatorID="0" nodeType="1061" template="0" sortOrder="6" createDate="2011-08-05T12:59:58" updateDate="2011-08-05T16:21:10" nodeName="3d" urlName="3d" writerName="Toni Becker" creatorName="Toni Becker" path="-1,1069,1072,1171" isDoc="">
            <portfolioImages>
              <DAMP fullMedia="">
                <mediaItem>
                  <Image id="1161" version="16ac3c18-8af7-4c09-9c95-249dd48c32ba" parentID="1121" level="4" writerID="0" nodeType="1032" template="0" sortOrder="3" createDate="2011-08-05T12:50:49" updateDate="2011-08-05T12:50:49" nodeName="3d3.jpg" urlName="3d3.jpg" writerName="Toni Becker" nodeTypeAlias="Image" path="-1,1046,1049,1121,1161">
                    <umbracoFile>/media/1161/3d3.jpg</umbracoFile>
                    <umbracoWidth>1024</umbracoWidth>
                    <umbracoHeight>768</umbracoHeight>
                    <umbracoBytes>248974</umbracoBytes>
                    <umbracoExtension>jpg</umbracoExtension>
                    <captionText />
                    <captionText2 />
                    <portfolioThumbs>
                      <crops date="05/08/2011 12:50:50">
                        <crop name="Slideshow Groß" x="0" y="101" x2="1024" y2="666" url="/media/1161/3d3_Slideshow Groß.jpg" />
                        <crop name="Slideshow Klein" x="0" y="111" x2="1024" y2="656" url="/media/1161/3d3_Slideshow Klein.jpg" />
                        <crop name="Slider Porfolio" x="11" y="0" x2="1011" y2="768" url="/media/1161/3d3_Slider Porfolio.jpg" />
                        <crop name="Unternehmen Slider" x="0" y="48" x2="1024" y2="718" url="/media/1161/3d3_Unternehmen Slider.jpg" />
                        <crop name="Leistung" x="128" y="0" x2="896" y2="768" url="/media/1161/3d3_Leistung.jpg" />
                        <crop name="Portfolio" x="0" y="88" x2="1024" y2="678" url="/media/1161/3d3_Portfolio.jpg" />
                        <crop name="Blog" x="0" y="251" x2="1024" y2="515" url="/media/1161/3d3_Blog.jpg" />
                        <crop name="Sidebar" x="0" y="33" x2="1024" y2="733" url="/media/1161/3d3_Sidebar.jpg" />
                      </crops>
                    </portfolioThumbs>
                    <portfolioVideoLink />
                    <portfolioTitel />
                    <portfolioText><![CDATA[]]></portfolioText>
                  </Image>
                </mediaItem>
                <mediaItem>
                    <Image>
                        <umbracoFile></umbracoFile>
                        <portfolioThumbs>
                        .....
                        </portfolioThumbs>
                    </Image>
                </mediaItem>
                <mediaItem>
                    <Image>
                        <umbracoFile></umbracoFile>
                        <portfolioThumbs>
                        .....
                        </portfolioThumbs>
                    </Image>
                </mediaItem>
            </DAMP>
        </portfolioImages>
    </PortfolioItem>   

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Aug 09, 2011 @ 11:25
    Anthony Dang
    0

    Do you want 10 nodes from the first PortfolioItem and then 10 from the next PortfolioItem ?

    Or do you want just 10 portfolioImages from your entire site? 

    If it is the latter that you want then you can do this....

     

     

    @using umbracoMacroEngines;
    @using System.Linq
    @{

    var dampXml =newDynamicNode(-1).Descendants("portfolioImages").Items.OrderByDescending(x => x.GetProperty("yourDatePropertyAlias").Value).Take(10);

    foreach(var xml in dampXml){
    // get the umbracoFile value from the DAMP xml
    string url = 
    XDocument.Parse(xml).Descendants("umbracoFile").FirstOrDefault();

    // now do something with your image url 


    } 
  • Toni Becker 146 posts 425 karma points
    Aug 09, 2011 @ 12:04
    Toni Becker
    0

    Throws an error:

    Error loading Razor Script ~/macroscripts/startseiteportfolio.cshtml
    c:\inetpub\wwwroot\3dHTML5\macroScripts\StartseitePortfolio.cshtml(9): error CS1502: The best overloaded method match for 'System.Xml.Linq.XDocument.Parse(string)' has some invalid arguments

    i referrenced @using System.Linq and @using System.Xml.Linq and @using System.Xml :/

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Aug 09, 2011 @ 12:51
    Anthony Dang
    0

    My bad...

    I think this will work...

    dampXml was meant to be an IEnumberable<string>

     

    @using umbracoMacroEngines;
    @usingSystem.Linq
    @{

    var dampXml =newDynamicNode(-1).Descendants("PortfolioItem").Items.OrderByDescending(x => x.GetProperty("yourDatePropertyAlias").Value).Select(x => x.GetProperty("portfolioImages")).Take(10);

    foreach(var xml indampXml){
    // get the umbracoFile value from the DAMP xml
     string url =
    XDocument.Parse(xml).Descendants("umbracoFile").FirstOrDefault();

    // now do something with your image url


    }

     

  • Toni Becker 146 posts 425 karma points
    Aug 09, 2011 @ 16:41
    Toni Becker
    0

    hmm same problem appearing :;/

Please Sign in or register to post replies

Write your reply to:

Draft