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
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!
Find Content by parentId and Content name
is working on a reply...