Copied to clipboard

Flag this post as spam?

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


  • Doug 2 posts 22 karma points
    Aug 28, 2013 @ 19:21
    Doug
    0

    Find Content by parentId and Content name

    I apologize if this has been asked before, but I couldn't find a solution after hours of searching.
    
    I am trying to create Content in Umbraco 6.0 in a stand-alone application.  Before I create the Content, I need to ensure the content does not already exist (either published or not), and the only way I've figured out how to do this is to get all contents for the given parentId and check if the name matches.Sorry, this is vb:  
    
    Dim parent As IContent = ContentService.GetById(parentId)    
    Dim contentsWithName As IEnumerable(Of IContent) =         
        parent.Children().Where(Function(child) child.Name = childName)   
    If contentsWithName IsNot Nothing Then     
      Return contentsWithName.First()    
    End If
    
    
    The above works, it's just slow because there are 10,000s of Content items with the given parentId.Is there a better way to do this so that it will work quickly?  It takes about 20 seconds to do the above search.
    
    Thanks
    
    -Doug
    
    
  • Doug 2 posts 22 karma points
    Aug 28, 2013 @ 22:09
    Doug
    0
    Nevermind...  I figured it out.
    
        Dim contents = ContentService.GetChildrenByName(parentId, childName)
        If contents IsNot Nothing Then
          Return contents.First()
        End If
    
    Don't know why I didn't see GetChildrenByName before...  It now takes less than a second to find it!
    
Please Sign in or register to post replies

Write your reply to:

Draft