Question

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
            }
        }
    }
}
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top