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

相關問題