Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
879 views
in Technique[技术] by (71.8m points)

api - Umbraco 4.6+ - How to get all nodes by doctype in C#?

Using Umbraco 4.6+, is there a way to retrieve all nodes of a specific doctype in C#? I've been looking in the umbraco.NodeFactory namespace, but haven't found anything of use yet.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was just doing this today, something like the below code should work (using umbraco.presentation.nodeFactory), call it with a nodeId of -1 to get the root node of the site and let it work it's way down:

private void DoSomethingWithAllNodesByType(int NodeId, string typeName)
{
    var node = new Node(nodeId);
    foreach (Node childNode in node.Children)
    {
        var child = childNode;
        if (child.NodeTypeAlias == typeName)
        {
            //Do something
        }

        if (child.Children.Count > 0)
            GetAllNodesByType(child, typeName);
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...