Dexter
Dexter

Reputation: 1178

Object error with trying to return documents (Umbraco Document API)

I'm working on a recursive method that displays all documents I have permissions to see. The first pass works great, but when it calls itself recursively passing a document array of the current document's children it throws an error:

Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Here's the code:

protected void Page_Load(object sender, EventArgs e)
{
    lblTest.Text = "Data<br /><br />";
    Document[] releaseDocs = Document.GetRootDocuments();
    displayDocs(releaseDocs);
}
public void displayDocs(Document[] releaseDocs)
{
    string docPermissions = null;
    User currentUser = User.GetCurrent();
    foreach (var doc in releaseDocs)
    {
        docPermissions = currentUser.GetPermissions(doc.Path);
        if ((docPermissions.Contains("F")) && (docPermissions.Contains("U")))
        {
            lblTest.Text += "D/T: " + doc.CreateDateTime + "<br />\r\n";
            lblTest.Text += "Level: " + doc.Level + "<br />\r\n";
            lblTest.Text += "Text: " + doc.Text + "<br />\r\n";
            lblTest.Text += "<hr />\r\n";
            if (doc.HasChildren)
            {
                 Document[] childDocs = Document.GetChildrenForTree(doc.Id);
                 displayDocs(childDocs); //error occurs here
            }
        }
    }
}

Upvotes: 0

Views: 326

Answers (1)

BeaverProj
BeaverProj

Reputation: 2215

Is it possible that the Document.GetChildrenForTree(doc.Id) method returns a null?

Upvotes: 1

Related Questions