0

我正在处理递归方法,该方法显示我有权查看的所有文档。第一遍的伟大工程,但是当它递归调用自己通过当前文档的儿童的文件阵列,它抛出一个错误:尝试返回文档时出现对象错误(Umbraco Document API)

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.

下面的代码:

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 
      } 
     } 
    } 
} 

回答

1

难道文档.GetChildrenForTree(doc.Id)方法返回null?

+0

我想到了这一点,并放弃了尝试。尽管如此,它仍然失败。在我称之前,我也证实HasChildren被设置为true。并不是说你可以依靠那个,但理论上如果它“有”孩子,那么它不应该是空的。 – Dexter 2011-05-05 18:06:25

+0

这可能是在our.umbraco.org上询问的问题 – BeaverProj 2011-05-05 23:55:47

相关问题